jtlindsey
jtlindsey

Reputation: 4863

How to view all "Connections" being referenced from heroku pg:info?

When I run heroku pg:info or heroku pg:info -a appname it returns

=== DATABASE_URL
Plan:        Hobby-dev
Status:      Available
Connections: 2/20
PG Version:  9.4.4
...

and the "Connections" line says 2/20. I expect 1 of those connections is the connection generated when I am running the above query. But I can't figure out what the other connection is. I have google analytics running on my application and live statistics show no users. My pg user query in another terminal window also returns no users are logged in. Connections shows 3 if I run heroku pg:info in another terminal while doing a user query (still one connection unaccounted for).

Currently I can only think of the following connection possibilities:

  1. Users logged into the web interface for the app (in my case none)
  2. Users logged into the app via terminal (per terminal instance...in my case 1 when running heroku pg:info (connections should say 1/20 but says 2/20) or 2 if I run that command while another terminal is open running heroku run rails c. So when I would expect connections to say 2/20 in this example, it says 3/20.

Either way, there is always 1 more connection than I can account for. When I look through documentation on heroku's website all I was able to find was ways to increase available connections. Not what connections represents.

How do I view all "Connections" being referenced from heroku pg:info?

Upvotes: 2

Views: 497

Answers (2)

rwg05
rwg05

Reputation: 137

Eight years late, but for those finding this answer through searching:

From: https://help.heroku.com/WJPVYSCG/what-is-using-up-my-postgres-connections

$ heroku pg:psql -c 'select usename, application_name, backend_start, query, wait_event, backend_type from pg_stat_activity;' --app my-app-name

Upvotes: 0

Simone Carletti
Simone Carletti

Reputation: 176502

Rails uses a connection pool, therefore the number of connections you see may be related to other non-active users that caused a connection to be opened and it has not been recycled yet by the pool.

Moreover, to connect to PG from the Heroku addon and get the stats you actually open a connection to it. That counts against the total number of opened connection, in addition to the ones opened by web requests from visitors).

Upvotes: 1

Related Questions