Created
February 27, 2017 22:09
-
-
Save ShawnMTherrien/7f228130da837d85a5cdb828c67d0c19 to your computer and use it in GitHub Desktop.
PGSQL - DBA - Blocking Queries
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 | |
bl.pid as Blocked_PID, | |
a.usename as Blocked_User, | |
a.query as blocked_query, | |
kl.pid as Blocking_PID, | |
ka.usename as Blocking_User, | |
ka.query as blocking_query, | |
kl.locktype, | |
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 join pg_catalog.pg_stat_activity ka on kl.pid = ka.pid) | |
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 | |
WHERE kl.granted and not bl.granted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment