How to see active SQL queries and open connections in Postgres?

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.

  1. Login to the PostgresSQL command-line interface
  2. psql -U [username] [database_name]

  3. Run the following query:
  4. SELECT datname,usename,procpid,client_addr,waiting,query_start,current_query FROM pg_stat_activity;


{ 1 Comments }
  1. I want to ask how to know what’s query if the idle status

Please post your comments/suggestions!