Skip to content

Instantly share code, notes, and snippets.

@skehlet
Created August 28, 2015 17:16
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 skehlet/fbf5f52e18149e14e520 to your computer and use it in GitHub Desktop.
Save skehlet/fbf5f52e18149e14e520 to your computer and use it in GitHub Desktop.
SELECT
COALESCE(blockingl.relation::regclass::text,blockingl.locktype) as locked_item,
blockeda.procpid AS blocked_pid,
blockeda.current_query as blocked_query,
blockedl.mode as blocked_mode,
blockinga.procpid AS blocking_pid,
blockinga.current_query as blocking_query,
blockingl.mode as blocking_mode
FROM pg_catalog.pg_locks blockedl
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.procpid
JOIN pg_catalog.pg_locks blockingl ON (
( blockingl.transactionid=blockedl.transactionid
OR
(blockingl.relation=blockedl.relation AND blockingl.locktype=blockedl.locktype)
)
AND blockedl.pid != blockingl.pid
)
JOIN pg_stat_activity blockinga ON blockingl.pid = blockinga.procpid
WHERE NOT blockedl.granted;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment