Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

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

select *
from pg_stat_activity
where datname = 'mydatabasename'
share|improve this answer
add comment

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

share|improve this answer
add comment

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
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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