[英]How to find which application reserved Postgres connections?
There are several applications running on Tomcat. Tomcat上运行着几个应用程序。 They use Postgres databases and sometimes exceed the max connection limit: 他们使用Postgres数据库,有时超过最大连接限制:
org.hibernate.exception.GenericJDBCException: Error calling Driver#connect at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
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:684)
I have tried to increase the limit ( How to resolve FATAL: connection limit exceeded for non-superusers ) but the problem remains. 我试图增加限制( 如何解决致命问题:非超级用户超出了连接限制 ),但问题仍然存在。 How to find out which application takes over connection slots? 如何找出哪个应用程序接管了连接插槽?
Add ApplicationName to the connection string, like here: 将ApplicationName添加到连接字符串,如下所示:
jdbc:postgresql://localhost:5435/MyDB?ApplicationName=MyApp
then you will see it in: 那么您将在以下位置看到它:
select application_name, count(1), state
from pg_stat_activity
group by application_name, state;
This will work only if you have separate connection strings for different applications of course. 当然,仅当您为不同的应用程序使用单独的连接字符串时,此方法才有效。
Also check some info on connections pooling with JDBC. 还要检查有关使用JDBC连接池的一些信息 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.