Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
from PostgreSQL 9.0 on you will even see the name of the application causing the problem. maybe this is helpful for future checks. – postgresql007 Apr 5 '10 at 18:19

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

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

See also pg-top, 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

Reference taken from this article.

FROM pg_stat_activity
WHERE state <> 'idle'
AND pid<>pg_backend_pid();
share|improve this answer
query and pid were named current_query and procpid, and state is not available in pg_stat_activity prior to PostgreSQL 9.2. – cpburnz May 3 at 3:27

Your Answer


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.