3

I'm developing an app on Spring 4.1 ,Tomcat 8.5.30 with a Postgresql 9.6 Periodically, I get this error message when trying to access the database, or when i run maven install twice successively :

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)

...

I actually tried to implement connection pooling of Tomcat org.apache.tomcat.jdbc.pool.DataSourceFactory, but i still have the problem.

A part of 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"
        />  

Anyone seen this before or please help point me in the right direction?

ines farhani
  • 41
  • 1
  • 5
  • Possible duplication of [this](https://stackoverflow.com/questions/47651864/caused-by-org-postgresql-util-psqlexception-fatal-remaining-connection-slots)? – JO3-W3B-D3V Jun 19 '19 at 13:41
  • thanks , i modified the context.xml but i still have the problem – ines farhani Jun 19 '19 at 15:46
  • `minIdle > maxIdle` looks weird. [maxTotal](https://tomcat.apache.org/tomcat-8.5-doc/jdbc-pool.html) doesn't exist in configuration it seems. – LMC Jun 19 '19 at 17:14
  • yes i corrected my context.xml – ines farhani Jun 20 '19 at 08:57
  • 1
    Possible duplicate of [Caused by: org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections](https://stackoverflow.com/questions/47651864/caused-by-org-postgresql-util-psqlexception-fatal-remaining-connection-slots) (your postgresql database is refusing new connections. Check how many open connections there are, whether that's normal, and either increase the max number in the DB's settings or find a way to reduce the amount of connections) – Aaron Jun 20 '19 at 09:02

1 Answers1

1

I checked how many open connections there are by :SELECT * FROM pg_stat_activity; I found many Idl connections and every time i run the install this number increase and exceeds "max-connection= 100" of postgresql . So i solved the problem by modifying minIdle="10" -> "0"

ines farhani
  • 41
  • 1
  • 5