The meaning of life is to explore the world

Postgres connection maxed out for Hikari Connection Pool

Posted on By Jason Liu

Error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  sorry, too many clients already

Warning:

com.zaxxer.hikari.pool.PoolBase(line:179) - HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@765d7657 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.

Trouble shooting:

docker exec -it ff76fc38b49a psql -U <db_user> -d <db_name> -c "SELECT count(*) FROM pg_stat_activity;"

Solution:
   Set a shorter maxLifetime (also idleTimeout if necessary) setMaxLifetime(N * 60 * 1000)
   Or, set minimumIdle to 0 in worst case

HikariCP document to set maxLifetime for reference:
   https://github.com/brettwooldridge/HikariCP?tab=readme-ov-file#gear-configuration-knobs-baby