Created
February 11, 2021 13:35
-
-
Save gsmolk/890e4175851865211984d50b3d45db46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
COALESCE(blockingl.relation::regclass::text,blockingl.locktype) as locked_item, | |
blockeda.pid AS blocked_pid, blockeda.query as blocked_query, | |
blockedl.mode as blocked_mode, blockinga.pid AS blocking_pid, | |
blockinga.query as blocking_pid_current_query, blockingl.mode as blocking_mode, | |
blockeda.state as blocked_state, blockinga.state as blocker_state, | |
blockingl.granted as blocker_granted, | |
blockingl.locktype as blocker_type, | |
NOW() - blockeda.query_start AS duration, blockeda.datname | |
FROM pg_catalog.pg_locks blockedl | |
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid | |
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.pid | |
WHERE NOT blockedl.granted ORDER BY duration DESC; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment