我在我的 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
2018-06-13 09:29:47.311 [ERROR] [main] [logging.DirectJDKLog:181 ] Unable to create initial connections of pool. org.postgresql.util.PSQLException: FATAL: désolé, trop de clients sont déjà connectés at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:443) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:217) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) at org.postgresql.jdbc.PgConnection.(PgConnection.java:215) at org.postgresql.Driver.makeConnection(Driver.java:404) at org.postgresql.Driver.connect(Driver.java:272) at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735) at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667) at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482) at org.apache.tomcat.jdbc.pool.ConnectionPool.(ConnectionPool.java:154) at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
最佳答案
检查 postgresql.conf 文件中的参数 max_connections 以及 application.yml 中显示的连接总数
ALTER SYSTEM SET max_connections ='150';
并使用
重启你的实例select pg_reload_conf();
注意:连接数取决于事件连接和空闲连接,设置更多连接数会过度杀死进程。
关于spring boot postgres : FATAL: sorry, 已经有太多客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50833023/