gpt4 book ai didi

java - Caused by : org. postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication super 用户连接

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:46 24 4
gpt4 key购买 nike

我使用 c3p0-0.9.5.2.jar 和 mchange-commons-java-0.2.11.jar 来管理池连接,我使用 postgreSql 9.3。

我在 Prod 环境中每天至少收到一次这些消息:

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 212 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1469)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
... 215 more
Caused by: org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:712)

我的应用程序中有这个配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver"/>

<property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/Test"/>

<property name="user" value="postgres"/>
<property name="password" value="postgres"/>
<!-- pool sizing -->
<!-- pool sizing -->
<property name="initialPoolSize" value="32" />
<property name="minPoolSize" value="30" />
<property name="maxPoolSize" value="300" />
<property name="acquireIncrement" value="10" />
<property name="maxStatements" value="0" />

<!-- retries -->
<property name="acquireRetryAttempts" value="30" />
<property name="acquireRetryDelay" value="1000" /> <!-- 1s -->
<property name="breakAfterAcquireFailure" value="false" />

<!-- refreshing connections -->
<property name="maxIdleTime" value="180" /> <!-- 3min -->
<property name="maxConnectionAge" value="10" /> <!-- 1h -->

<!-- timeouts and testing -->
<property name="checkoutTimeout" value="0" /> <!-- 60s -->
<property name="idleConnectionTestPeriod" value="60" /> <!-- 60 -->
<property name="testConnectionOnCheckout" value="true" />
<property name="preferredTestQuery" value="SELECT 1" />
<property name="testConnectionOnCheckin" value="true" />

</bean>
</beans>

在 postgresql.conf 中我有这个配置:

max_connections = 300
shared_buffers = 32GB

我的服务器有这样的性能:24 cpu,256 GB 内存

使用该应用的用户数量在1300左右

有没有人可以帮我解决这个问题

提前谢谢你

最佳答案

superuser_reserved_connections 个连接槽(默认为 3 个)是为 super 用户保留的,这样他们即使在所有连接槽都被占用的情况下也可以连接。

所以您实际上只有 297 个可用插槽。

要么减少连接池的最大连接数,要么增加 PostgreSQL 中的 max_connections

顺便说一下,300 太高了。您应该对连接池使用低得多的设置(除非您的数据库计算机中有数百个内核)。

关于java - Caused by : org. postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication super 用户连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47651864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com