我正在使用连接到pgpool2的Liferay集群,当我对Web服务器运行大量的用户活动时,我发现很多关于liferay无法build立到数据库连接的exception。 在pgpool后面有两个数据库
例外情况
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! ---------- Caused by: com.mchange.v2.resourcepool.ResourcePoolException: A ResourcePool cannot acquire a new resource -- the factory or source appears to be down. org.postgresql.util.PSQLException: The connection attempt failed. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:152) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146) at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195) at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:211) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086) at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073) at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44) at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648) Caused by: java.io.EOFException at org.postgresql.core.PGStream.ReceiveInteger4(PGStream.java:289) at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:282) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) ... 14 more ------ 02:34:55,197 WARN [C3P0PooledConnectionPoolManager[identityToken->Q5VpVuN8]-HelperThread-#0][BasicResourcePool:894] Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@427db1c2 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
我有liferay设置使用C3p0,我configuration的数据库是pgpool2。 我已经玩了好几天了,尝试了数十万个组合,我认为我处于最佳状态,但还没有到现在,我也不是DBA。 Liferayconfiguration了相同的用户/密码,所以我认为pgpool会重新使用caching的连接,但我无法确定问题。 这是我的configuration
postgresconfiguration
max_connections = 200 shared_buffers = 100MB
pgpool2configuration
num_init_children = 500 max_pool = 10 child_max_connections = 4950 child_life_time = 300 connection_life_time = 0 client_idle_limit = 0
Liferayconfiguration
jdbc.default.acquireIncrement=5 jdbc.default.acquireRetryAttempts=3 jdbc.default.acquireRetryDelay=1000 jdbc.default.connectionCustomizerClassName=com.liferay.portal.dao.jdbc.pool.c3p0.PortalConnectionCustomizer jdbc.default.idleConnectionTestPeriod=60 jdbc.default.maxIdleTime=3600 jdbc.default.maxPoolSize=1000 jdbc.default.minPoolSize=10 jdbc.default.numHelperThreads=100
我应该增加在pgpool后面的数据库服务器上的max_connections吗? 或者改变pgpool参数
num_init_children = 10 max_pool = 500 child_max_connections = 4950 connection_life_time = 0 client_idle_limit = 0
任何帮助表示赞赏!
从pgpool-II用户手册
max_pool*num_init_children <= (max_connections - superuser_reserved_connections)
如果你需要500个并发连接到pgpool,那么在你的Postgresconfiguration中你需要更多的max_connections 。 因此,对于500个并发连接,您需要:
在pgpool.conf :
num_init_children = 500 max_pool = 1 # there's no need for more if you don't use different credentials
在postgresql.conf :
max_connections = 550
另外 – 我不认为你应该使用C3PO和PgPool-II – 没有意义的堆叠两个连接沉闷的对方。 另外我不认为你应该使用多个数据库 。