Advertisement
emssik

SQL - PostgreSQL - find locked transactions

Oct 9th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.60 KB | None | 0 0
  1. SELECT bl.pid AS blocked_pid, a.usename AS blocked_user,
  2.         ka.current_query AS blocking_statement, now() - ka.query_start AS blocking_duration,
  3.         kl.pid AS blocking_pid, ka.usename AS blocking_user, a.current_query AS blocked_statement,
  4.         now() - a.query_start AS blocked_duration
  5.  FROM pg_catalog.pg_locks bl
  6.       JOIN pg_catalog.pg_stat_activity a
  7.       ON bl.pid = a.procpid
  8.       JOIN pg_catalog.pg_locks kl
  9.            JOIN pg_catalog.pg_stat_activity ka
  10.            ON kl.pid = ka.procpid
  11.       ON bl.transactionid = kl.transactionid AND bl.pid != kl.pid
  12.  WHERE NOT bl.GRANTED;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement