2

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.

  1. 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.

  2. 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'.

udit
  • 2,745
  • 3
  • 33
  • 44

1 Answers1

0

pg_stat_activity shows data for the server:

The pg_stat_activity view will have one row per server process, showing information related to the current activity of that process.

Note that this information is not restricted to any particular database. With Heroku Postgres, you don't get a dedicated server. Other users' databases will be running on the same server, so the data you see there includes those users' connections.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257