Skip to content

Instantly share code, notes, and snippets.

@beck03076
Created March 28, 2017 05:02
Show Gist options
  • Save beck03076/0e0cd0f465895ed72ce52dd0b812a06a to your computer and use it in GitHub Desktop.
Save beck03076/0e0cd0f465895ed72ce52dd0b812a06a to your computer and use it in GitHub Desktop.
We used this query to find out the number of pg connections,
select count(*) from pg_stat_activity
We investigated and found out the there were multiple(upto 17) pg connections from 2 sidekiq processes
we have with 40 concurrent threads.
We used this query to find out sidekiq pg connections,
select pid, usename, application_name, state from pg_stat_activity where usename = 'ringmdstaging' and application_name like 'sidekiq%';
select count(*) where usename = 'ringmdstaging' and application_name like 'sidekiq%';
We found that the 'max_connections' config variable in /opt/bitnami/postgresql/conf/postgresql.conf is 100.
Then we increased that to 250.
We wrote a shell script to establish 250 pg connections using this,
for i in {1..250}
do
psql -U postgres &
done
Then this query output 250 pg connections.
postgres=# select count(*) from pg_stat_activity ;
count
-------
250
(1 row)
We tried rails console, We got FATAL: sorry, too many clients already (PG::ConnectionBad)
Then we killed the duplicate pg connections and tried rails console, it worked.
Though this is not the same error, our initial error was "FATAL: remaining connection slots are reserved
for non-replication superuser connections", this github issue seem to prove that "max_connections" fixes this,
https://github.com/Netflix/security_monkey/issues/185
This is a temporary fix, a permanent fix to this is to setup Postgres Pooling.
https://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling
Thanks - Duc & Senthil.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment