-
-
Save dxe4/1702c21544a37a2cb7b37640a4a956a7 to your computer and use it in GitHub Desktop.
postgresql locked queries
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
WITH _locks AS ( | |
SELECT | |
PL.pid, unnest(pg_blocking_pids(PL.pid)) AS blocking_pid | |
FROM pg_locks PL | |
WHERE NOT granted | |
) | |
select | |
PSA.pid AS query_pid, | |
LEFT(query, 200) AS query, | |
CASE | |
WHEN PSA.pid = L.pid THEN 'blocked' | |
WHEN PSA.pid = L.blocking_pid THEN 'blocking' | |
END AS status, | |
L.pid AS blocked_query_pid, | |
L.blocking_pid, | |
PSA.application_name, | |
PSA.state AS transaction_state, | |
PSA.backend_xid, | |
PSA.query_start | |
FROM _locks L | |
JOIN pg_stat_activity PSA ON ( | |
PSA.pid = L.pid OR | |
PSA.pid = L.blocking_pid | |
) | |
ORDER BY PSA.query_start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment