Created
September 30, 2016 12:21
-
-
Save moofkit/2146f18953be9053ae372c063d28912b to your computer and use it in GitHub Desktop.
lock monitor. postgresql
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
CREATE VIEW lock_monitor AS | |
SELECT COALESCE(((blockingl.relation)::regclass)::text, blockingl.locktype) AS locked_item, | |
(now() - blockeda.query_start) AS waiting_duration, | |
blockeda.pid AS blocked_pid, | |
blockeda.query AS blocked_query, | |
blockedl.mode AS blocked_mode, | |
blockinga.pid AS blocking_pid, | |
blockinga.query AS blocking_query, | |
blockingl.mode AS blocking_mode | |
FROM (((pg_locks blockedl | |
JOIN pg_stat_activity blockeda ON ((blockedl.pid = blockeda.pid))) | |
JOIN 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) AND (blockinga.datid = blockeda.datid)))) | |
WHERE ((NOT blockedl.granted) AND (blockinga.datname = current_database())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment