Skip to content

Instantly share code, notes, and snippets.

@pshen
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pshen/5a6e92aa20d8c091821d to your computer and use it in GitHub Desktop.
Save pshen/5a6e92aa20d8c091821d to your computer and use it in GitHub Desktop.
Who is blocking? PG>9.2
SELECT
w.query as waiting_query,
w.pid as w_pid,
w.usename as w_user,
l.query as locking_query,
l.pid as l_pid,
l.usename as l_user,
t.schemaname || '.' || t.relname as tablename
from pg_stat_activity w
join pg_locks l1 on w.pid = l1.pid and not l1.granted
join pg_locks l2 on l1.relation = l2.relation and l2.granted
join pg_stat_activity l on l2.pid = l.pid
join pg_stat_user_tables t on l1.relation = t.relid
where w.waiting;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment