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);