简体   繁体   English

引起:org.postgresql.util.PSQLException:致命:剩余的连接槽是为非复制超级用户连接保留的

[英]Caused by: org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections

I use c3p0-0.9.5.2.jar and mchange-commons-java-0.2.11.jar to manage the pool connection, And I use postgreSql 9.3.我使用 c3p0-0.9.5.2.jar 和 mchange-commons-java-0.2.11.jar 来管理池连接,我使用 postgreSql 9.3。

I get these messages at least once a day in my Prod environment :在我的 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)

I have this config in my aplication :我的应用程序中有这个配置:

<?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>

in postgresql.conf I have this config :在 postgresql.conf 我有这个配置:

max_connections = 300
shared_buffers = 32GB

my server has this performance: 24 cpu, 256 GB memory我的服务器有这样的性能: 24 cpu,256 GB 内存

the number of users using the application is around 1300使用该应用程序的用户数量约为 1300

is there anyone who can help me to solve this problem有没有人可以帮我解决这个问题

thank you in advance提前谢谢你

There are superuser_reserved_connections connections slots ( 3 by default ) that are reserved for superusers so that they can connect even in a situation where all connection slots are taken.有为超级用户保留的superuser_reserved_connections连接槽(默认3 ),以便他们即使在所有连接槽都被占用的情况下也可以连接。

So you effectively only have 297 slots available.因此,您实际上只有 297 个可用插槽。

Either reduce the maximum number of connections of your connection pool or increase max_connections in PostgreSQL.减少连接池的最大连接数或增加max_connections中的max_connections

By the way, 300 is much too high.顺便说一句,300太高了。 You should use a much lower setting with a connection pool (unless you have hundreds of cores in your database machine).您应该对连接池使用更低的设置(除非您的数据库机器中有数百个内核)。

The error you are seeing is an indication that postgres does not have any more connections available.您看到的错误表明 postgres 没有更多可用连接。

Run this command on your SQL database to see if you can better understand what commands/users are using up so many connections :在您的 SQL 数据库上运行此命令,看看您是否能更好地了解哪些命令/用户正在使用这么多连接:

 select * from pg_stat_activity;

If you just want to know the count of open connections, use :如果您只想知道打开连接的数量,请使用:

SELECT count(*) FROM pg_stat_activity;

Sometimes the number of open connections reaches the max_connections limit.有时打开的连接数达到 max_connections 限制。

For me, restarting the pgAdmin app resolved the issue.对我来说,重新启动 pgAdmin 应用程序解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:org.postgresql.util.PSQLException:致命:用户“admin”的密码验证失败 - Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin" org.postgresql.util.PSQLException:连接尝试失败。 引起:java.net.UnknownHostException - org.postgresql.util.PSQLException: The connection attempt failed. Caused by: java.net.UnknownHostException 引起:org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" org.postgresql.util.PSQLException:致命:数据库“pma-springbootdb” - org.postgresql.util.PSQLException: FATAL: database “pma-springbootdb” org.postgresql.util.PSQLException:致命:数据库“ postgres&gt;”不存在 - org.postgresql.util.PSQLException: FATAL: database “postgres>” does not exist org.postgresql.util.PSQLException:连接尝试失败 - org.postgresql.util.PSQLException: The connection attempt failed ClassNotFoundException:org.postgresql.util.PSQLException - ClassNotFoundException: org.postgresql.util.PSQLException org.postgresql.util.PSQLException - 2019 - org.postgresql.util.PSQLException - 2019 引起:org.postgresql.util.PSQLException:尝试自动创建数据库时数据库不存在 - Caused by: org.postgresql.util.PSQLException: database doesn't exist when trying to auto-create database 引起:org.postgresql.util.PSQLException:错误:PL/pgSQL 函数上的配置参数无法识别 - Caused by: org.postgresql.util.PSQLException: ERROR: unrecognized configuration parameter on PL/pgSQL function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM