This article will show you how to see a list of open database connections as well as all active queries that are running on a PostgresSQL 8.x database. This information can be very beneficial when profiling your application and determining queries that have “gone wild” and are eating CPU cycles.
- Login to the PostgresSQL command-line interface
- Run the following query:
psql -U [username] [database_name]
SELECT datname,usename,procpid,client_addr,waiting,query_start,current_query FROM pg_stat_activity;
I want to ask how to know what’s query if the idle status
Hi!
The Query does not work for newer Versions of PostgreSQL. ‘procpid’ was renamed to ‘pid’ and ‘current_query’ is ‘query’ now. So:
SELECT datname,usename,pid,client_addr,waiting,query_start,query FROM pg_stat_activity;
Sebastian
How about select query from pg_stat_activity;
“\c” is not working in windows – psql
How to clear that error…….?
ERROR: syntax error at or near “\”
LINE 3: \c busservice
^
********** Error **********
ERROR: syntax error at or near “\”
SQL state: 42601
Character: 67
postgres=# SELECT datname,usename,procpid,client_addr,waiting,query_start,current_query FROM pg_stat_activity;
ERROR: column “procpid” does not exist
???