Created
September 15, 2015 16:14
-
-
Save franklinbr/57ff2b78aa2100c7761b 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 kl.pid AS blocking_pid, | |
ka.usename AS blocking_user, | |
ka.query AS blocking_query, | |
bl.pid AS blocked_pid, | |
a.usename AS blocked_user, | |
a.query AS blocked_query, | |
To_char(Age(Now(), a.query_start),'HH24h:MIm:SSs') AS age | |
FROM pg_catalog.pg_locks bl | |
JOIN pg_catalog.pg_stat_activity a | |
ON bl.pid = a.pid | |
JOIN pg_catalog.pg_locks kl | |
ON bl.locktype = kl.locktype | |
AND bl.database IS NOT distinct | |
FROM kl.DATABASE | |
AND bl.relation IS NOT DISTINCT | |
FROM kl.relation | |
AND bl.page IS NOT DISTINCT | |
FROM kl.page | |
AND bl.tuple IS NOT DISTINCT | |
FROM kl.tuple | |
AND bl.virtualxid IS NOT DISTINCT | |
FROM kl.virtualxid | |
AND bl.transactionid IS NOT DISTINCT | |
FROM kl.transactionid | |
AND bl.classid IS NOT DISTINCT | |
FROM kl.classid | |
AND bl.objid IS NOT DISTINCT | |
FROM kl.objid | |
AND bl.objsubid IS NOT DISTINCT | |
FROM kl.objsubid | |
AND bl.pid <> kl.pid | |
JOIN pg_catalog.pg_stat_activity ka | |
ON kl.pid = ka.pid | |
WHERE kl.granted | |
AND NOT bl.granted | |
ORDER BY a.query_start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment