database 在配置的阻塞超时内没有可用的托管连接(JBoss 7 和 Postgres)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/17469743/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No managed connections available within configured blocking timeout (JBoss 7 and Postgres)
提问by Benjamin
Periodically i get error :
我定期收到错误:
ERROR JDBCExceptionReporter --> javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/myDB 08:12:05,928 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/mySoftware].[jsp]] (ajp--xx.255.0.yyy-8109-21) Servlet.service() for servlet jsp threw exception: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms]) at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:377) and etc.
错误 JDBCExceptionReporter --> javax.resource.ResourceException: IJ000453: 无法获得 java:jboss/datasources/myDB 的托管连接 08:12:05,928 错误 [org.apache.catalina.core.ContainerBase.[jboss.web].[ default-host].[/mySoftware].[jsp]] (ajp--xx.255.0.yyy-8109-21) servlet jsp 的 Servlet.service() 抛出异常:javax.resource.ResourceException:IJ000655:没有托管连接在 org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:377) 等配置的阻塞超时(30000 [ms])内可用。
.
.
So, i have next datasource config. on JBoss AS :
所以,我有下一个数据源配置。在 JBoss AS 上:
<datasource jta="true" jndi-name="java:jboss/datasources/myDB" pool-name="ssbs-pssbs" enabled="true" use-ccm="true">
                    <connection-url>jdbc:postgresql://xx.255.0.yyy/myDatabase</connection-url>
                    <driver-class>org.postgresql.Driver</driver-class>
                    <driver>postgresql-jdbc4</driver>
                    <pool>
                        <min-pool-size>30</min-pool-size>
                        <max-pool-size>150</max-pool-size>
                        <prefill>true</prefill>
                        <use-strict-min>false</use-strict-min>
                        <flush-strategy>FailingConnectionOnly</flush-strategy>
                    </pool>
                    <security>
                        <user-name>tick</user-name>
                        <password>tack</password>
                    </security>
                    <validation>
                        <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <timeout>
                        <blocking-timeout-millis>30000</blocking-timeout-millis>
                        <idle-timeout-minutes>5</idle-timeout-minutes>
                    </timeout>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
and in my Postgres server i allow max_connection on 500. Why i get this exception ?
在我的 Postgres 服务器中,我允许在 500 上使用 max_connection。为什么会出现此异常?
回答by Chris Travers
Your primary issue is probably a connection leak, but maybe not. In other words database transactions are leaving the pool and not being returned. In this case there are a few specific things to start with because the problem is probably a codeproblem and not a databaseproblem.
您的主要问题可能是连接泄漏,但也可能不是。换句话说,数据库事务正在离开池并且没有被返回。在这种情况下,有一些特定的事情要开始,因为问题可能是代码问题而不是数据库问题。
The first thing to check is the current status of everything in pg_stat_activity.  This includes the most recent query and the transaction state.  In a connection leak you will probably find a large number of IDLEconnections with similar queries.  The queries can help you track down the connection leak.  Also in a connection leak, when the problem starts, it will continue until you restart things.
首先要检查的是pg_stat_activity. 这包括最近的查询和交易状态。在连接泄漏中,您可能会发现大量IDLE具有类似查询的连接。这些查询可以帮助您追踪连接泄漏。同样在连接泄漏中,当问题开始时,它将一直持续到您重新启动。
In the event where the issue is in fact too few connections available, then you will see lots of ACTIVEconnections.  In that case increase the number of connections in your pool.  Also in this case, the problem will occur intermittently and then appear to go on its own all by itself.
如果问题实际上是可用连接太少,那么您会看到很多ACTIVE连接。在这种情况下,请增加池中的连接数。同样在这种情况下,问题会间歇性地发生,然后似乎会自行消失。

