I'm connecting to my postgres instance in springboot and I've implemented Hikari CP for connection pooling . I see after a few days of deployment , my code seems to break I seem to get the following error message in my logs
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 60000ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:602)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:195)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
atcom.dell.it.daas.apibuilder.submitrequestservice.Services.PostgresConnectionServiceImpl.connectToPostgresDatabase(PostgresConnectionServiceImpl.java:103)
at com.dell.it.daas.apibuilder.submitrequestservice.Services.PostgresConnectionServiceImpl.getRequestDetailsByRequestId(PostgresConnectionServiceImpl.java:114)
Here's my Hikari CP connection parameters
public static Connection connectToPostgresDatabase(String connectionString, String userName, String
password)
throws SQLException {
if (config == null) {
config = new HikariConfig();
config.setJdbcUrl(connectionString);
config.setUsername(userName);
config.setPassword(password);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "256");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setConnectionTimeout(60000);
config.setMinimumIdle(10);
config.setMaximumPoolSize(30);
config.setLeakDetectionThreshold(60000);
config.setConnectionTestQuery("SELECT 1");
config.setInitializationFailTimeout(20000);
config.addDataSourceProperty("prepareThreshold", 0);
config.addDataSourceProperty("useServerPrepStmts", true);
ds = new HikariDataSource(config);
}
return ds.getConnection();
}
SO whenever I need to execute any Query I get the connection to database as
try(Connection con =
PostgresConnectionServiceImpl.connectToPostgresDatabase(apibuilderConnectionString,
apibuilderUserName, apibuilderPassword))
{
if(getSchema()!=null)
con.setSchema(getSchema());
try(PreparedStatement st = con.prepareStatement(queryToRetrieveRequestDetails);
ResultSet requestDetailsSet = st.executeQuery();)
I'm using try with resources to do all my database related operations
PostgresConnectionServiceImpl.connectToPostgresDatabase(apibuilderConnectionString,
apibuilderUserName, apibuilderPassword)
This is the the line which is failing .
Been struggling with this for some time now appreciate any help . Thanks