Check queries or sessions that are currently running in PostgreSQL

Check the currently executing queries in PostgreSQL

Check queries that are currently running in PostgreSQL

SELECT client_addrSELECT client_addr, query_start, query
  FROM pg_stat_activity
 WHERE state IN ('active', 'idle in transaction')
   AND backend_type = 'client backend';

Check the session user or process id that is currently executing queries in PostgreSQL

SELECT pid,user,client_addr, query_start, query
  FROM pg_stat_activity
 WHERE state IN ('active', 'idle in transaction')
   AND backend_type = 'client backend';

If you want to kill the query or session then

-- For Query: It is a clean kill, so it take time to complete.
SELECT pg_cancel_backend(PID);

--For Session: It is the hard way to kill the session
SELECT pg_terminate_backend(PID);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.