我正在Spring 4.1,Tomcat 8.5.30和Postgresql 9.6上开发一个应用程序,当我尝试访问数据库或连续两次运行maven install时,会收到此错误消息:
AVERTISSEMENT [http-nio-9000-exec-36]
org.apache.naming.NamingContext.lookup Une erreur s est produite durant
la résolution de la référence
org.postgresql.util.PSQLException: FATAL: remaining connection slots are
reserved for non-replication superuser connections
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:691)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:207)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:156)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:35)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:47)
at org.postgresql.jdbc42.AbstractJdbc42Connection.<init>(AbstractJdbc42Connection.java:21)
at org.postgresql.jdbc42.Jdbc42Connection.<init>(Jdbc42Connection.java:28)
at org.postgresql.Driver.makeConnection(Driver.java:415)
at org.postgresql.Driver.connect(Driver.java:282)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:319)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:212)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:736)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:668)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:483)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:560)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:244)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:839)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
...
我实际上试图实现Tomcat org.apache.tomcat.jdbc.pool.DataSourceFactory的连接池,但是仍然有问题。
Context.xml的一部分:
<Resource name="jdbc/newmf01DataSource"
auth="Container"
type="javax.sql.DataSource"
username="xx"
password="xx"
driverClassName="org.postgresql.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer(trace=true);
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=1000,maxQueries=10000);
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx(notifyPool=false,objectName=tomcat.jdbc:type=org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx,name=jdbc/newmf01DataSource)"
url="jdbc:postgresql://dvdsi975.rouen.francetelecom.fr:5432/pnmf02"
validationQuery="SELECT 1"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
maxIdle="20"
maxActive="70"
minIdle="10"
initialSize="10"
logAbandoned="true"
removeAbandonedTimeout="60"
removeAbandoned="true"
minEvictableIdleTimeMillis="30000"
jmxEnabled="true"
useNaming="false"
maxWait ="10000"
/>
任何人以前都看过这个,还是请帮我指出正确的方向?
答案 0 :(得分:0)
我通过:SELECT * FROM pg_stat_activity;检查了多少个打开的连接。我发现有许多Idl连接,并且每次运行安装时,此数目都会增加,并超过postgresql的“ max-connection = 100”。 所以我通过修改minIdle =“ 10”->“ 0”
解决了问题