Is there a command in PostgreSQL to select active connections to a given database?
psql
states that I can't drop one of my databases because there are active connections to it, so I would like to see what the connections are (and from which machines)
Oh, I just found that command on PostgreSQL forum:
Following will give you active connections/ queries in postgres DB-
You may use 'idle' instead of active to get already executed connections/queries.
Since
pg_stat_activity
contains connection statistics of all databases having any state, eitheridle
oractive
, database name and connection state should be included in the query to get the desired output.