View blocked / blocking processes
SELECT DISTINCT
bl.procpid AS blocked_pid,
bl.usename AS USER,
bl.current_query AS blocked_query,
bl.query_start,
relname AS blocked_on,
lq.procpid AS blocking_pid,
lq.usename AS USER,
lq.current_query AS blocking_query,
lq.query_start,
pgl2.mode AS lock_type
FROM pg_stat_activity bl,
pg_locks pgl1,
pg_stat_activity lq,
pg_locks pgl2,
pg_class
WHERE bl.procpid = pgl1.pid
AND NOT pgl1.granted
AND pg_class.oid = pgl1.relation
AND pgl2.relation = pgl1.relation
AND pgl2.granted
AND lq.procpid = pgl2.pid;
Written by Matt Keranen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Hybriddba
Authors
datasaur
30.96K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#