I'm debugging issues with my postgres running out of connections to give so I decided to look under the hood for how many open connections currently exist, using:
SELECT sum(numbackends) FROM pg_stat_database;
I see 123 . Now that cant be right. Lets look at who's connecting to the DB:
SELECT application_name FROM pg_stat_activity order by application_name;
/app/bin/rails
/app/vendor/bundle/ruby/2.6.0/bin/puma
/app/vendor/bundle/ruby/3.0.0/bin/puma
/app/vendor/bundle/ruby/3.0.0/bin/puma
/app/vendor/bundle/ruby/3.0.0/bin/puma
/app/vendor/bundle/ruby/3.0.0/bin/rackup
bin/rails
bin/rails
bin/rails
bin/rails
DBeaver 22.1.4 - Main <d7i081pnvh4lhn>
DBeaver 22.1.4 - Metadata <d7i081pnvh4lhn>
GoodJob::Notifier
hc.dbmon
hc.dbmon
hc.dbmon
hc.dbmon
hc.dbmon
pgAdmin 4 - CONN:360832
pgAdmin 4 - DB:d912h2n04vgugu
PostgreSQL JDBC Driver
PostgreSQL JDBC Driver
PostgreSQL JDBC Driver
PostgreSQL JDBC Driver
... (40-50 rows of the same)
psql interactive
puma: cluster worker 0: 4 [app]
sidekiq 6.0.1 app [0 of 5 busy]
sidekiq 6.0.1 app [0 of 5 busy]
So that's weird, I just have a rails app using GoodJob. I dont use sidekiq, no business with JDBC or using DBeaver. It seems like I'm seeing the postgres connections from other users/apps that are sharing the postgres server instance.
Is this leaky abstraction normal? I would have expected a pretty air-tight lockdown of this information being shared between different app instances. There's no query information leaking but still.
Whats a straightforward way to my app's connections? What I'm currently doing is filtering out everything where the query is not 'Insufficient Privilege'.