Reconnect to database after lost of connection

Hi

I have currently the issue, that my webapp loose database connection and could not reconnect automatically.

I have a postgres database in the background that could be on high load sometimes.
Is there a way to configure the jdbc connection to automatically reconnect?

Thanks
Thomas

Hi,

I have a postgres database in the background that could be on high load sometimes

to automatically reconnect

High load of the database server can not be the reason to “loose connection”. CUBA application uses connection pool in front of the database and re-uses several connections many times. Connection pools do reconnection when necessary.

Which connection pool do you use?
Default tomcat’s connection pool (commons dbcp 2) has a number of options which you can use to quickly recover after connection to database server has been lost and then restored, such as “testOnBorrow”, “removeAbandoned” etc.

http://tomcat.apache.org/tomcat-8.5-doc/jndi-datasource-examples-howto.html#Database_Connection_Pool_(DBCP_2)_Configurations
https://commons.apache.org/proper/commons-dbcp/configuration.html

Hi Alex

thanks for reply.

At the moment, I have configured the connection as followed in context.xml file:

driverClassName="org.postgresql.Driver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" validationQuery="SELECT 1" initialSize="0" maxActive="20" maxWaitMillis="10000" maxTotal="100" maxIdle="5" maxWait="10000" poolPreparedStatements="true" maxOpenPreparedStatements="100" removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true" removeAbandonedTimeout="60" logAbandoned="true" testOnBorrow="true"

Waiting now the result in some days as we have this error maybe once per month.

Thomas