spring boot postgres:致命:抱歉,已经有太多客户了

Aym*_*ari 5 postgresql spring jdbc spring-boot

我在 Spring Boot 应用程序中使用 postgres 作为数据库,当我运行我的应用程序时出现错误FATAL: sorry, too many clients already。我在 application.yml 中配置了一个连接池,但我仍然有同样的问题

spring:
  jpa:
    database: postgresql
    hibernate:
      ddl-auto: update
  datasource:
    url: jdbc:postgresql://localhost:5432/sp
    username: sp
    password: admin
    continueOnError: true
    platform: dev
    tomcat:
      maxIdle: 10
      max-active: 100
      max-wait: 10000
      validationQuery: select 1
      removeAbandoned: true
      removeAbandonedTimeout: 120
      logAbandoned: true
      testOnBorrow: true
      testOnConnect: true
      testWhileIdle: true
Run Code Online (Sandbox Code Playgroud)

2018-06-13 09:29:47.311 [ERROR] [main] [logging.DirectJDKLog:181] 无法创建池的初始连接。org.postgresql.util.PSQLException:致命:在 org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:443) 在 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl( ConnectionFactoryImpl.java:217) 在 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) 在 org.postgresql.jdbc.PgConnection.(PgConnection.java:215) 在 org.postgresql.Driver.makeConnection(Driver. java:404) 在 org.postgresql.Driver.connect(Driver.java:272) 在 org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) 在 org.apache.tomcat.jdbc.pool .PooledConnection。

Paw*_*rma 6

检查postgresql.conf 文件中的参数max_connections以及 application.yml 中显示的连接总数

ALTER SYSTEM SET max_connections ='150';
Run Code Online (Sandbox Code Playgroud)

并使用重新启动您的实例

select pg_reload_conf();
Run Code Online (Sandbox Code Playgroud)

注意:连接数取决于活动连接和空闲连接,在连接中设置更多数量会过度杀死进程。