Created
December 17, 2019 06:45
-
-
Save stultus/b619b0caccac9a35d317a8d5b643a754 to your computer and use it in GitHub Desktop.
script to find the cause of blocked transactions.
This file contains 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 | |
pl.pid as blocked_pid | |
,psa.usename as blocked_user | |
,pl2.pid as blocking_pid | |
,psa2.usename as blocking_user | |
,psa.query as blocked_statement | |
FROM pg_catalog.pg_locks pl | |
JOIN pg_catalog.pg_stat_activity psa | |
ON pl.pid = psa.pid | |
JOIN pg_catalog.pg_locks pl2 | |
JOIN pg_catalog.pg_stat_activity psa2 | |
ON pl2.pid = psa2.pid | |
ON pl.transactionid = pl2.transactionid | |
AND pl.pid != pl2.pid | |
WHERE NOT pl.granted; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment