I'm investigating an issue with DB connections being left open indefinitely, causing problems on the DB server. How do I see currently open connections to a PostgreSQL server, particularly those using a specific database? Ideally I'd like to see what command is executing there as well. Basically, I'm looking for something equivalent to the "Current Activity" view in MSSQL.

link|improve this question

53% accept rate
feedback

3 Answers

OK, got it from someone else. This query does the trick:

select *
from pg_stat_activity
where datname = 'mydatabasename'
link|improve this answer
feedback

from PostgreSQL 9.0 on you will even see the name of the application causing the problem. maybe this is helpful for future checks.

link|improve this answer
feedback

See also [pg-top][1], which acts like top except it shows postgres activity.

  • Install pg-top (in Debian, the package is called "ptop").
  • Become the postgres user (e.g. sudo su postgres)
  • Run pg_top
link|improve this answer
Can it work without root access on the machine? – EMP Nov 29 '10 at 22:02
@Evgeny, As far as I know, you have to be logged in as the postgres user. That should be possible without root access. – Wayne Conrad Nov 30 '10 at 14:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.