Thursday 1 August 2013

Postgres error: 'FATAL too many connections'

My daily work involves development with JBoss and Postgres (pgAdmin).
After many JBoss's redeployments (starts/stops/killings) and pgAdmin crashes
JBoss could not be started. More specifically on start time I got the following
exception:

Postgres error: 'FATAL too many connections'

I opened pgAdmin and executed the following script to get all open connection
on my database foodb:

SELECT * FROM pg_stat_activity
where datname='foodb';

At total 18...I guess this is the limit of the connections thread pool of Postgres
(normally pgAdmin uses 2 connections and JBoss (v5) 12 connections).

In order to kill all of them (stop first JBoss) I executed the following script:

select pg_terminate_backend(procpid) from pg_stat_activity where datname='foodb';

On a closer examination the reason was not closing my Hibernate sessions in my code; or pgAdmin not
closing sessions when it crashes; or JBoss letting connections open when killing it.

No comments:

Post a Comment