Skip to content

Instantly share code, notes, and snippets.

@dpirotte
Created May 19, 2011 20:36
Show Gist options
  • Save dpirotte/981683 to your computer and use it in GitHub Desktop.
Save dpirotte/981683 to your computer and use it in GitHub Desktop.
Find blocked queries
SELECT
l1.*,
l2.virtualtransaction,
l2.pid,
l2.mode,
l2.granted
FROM
pg_locks l1
JOIN
pg_locks l2 ON (
(
l1.locktype,
l1.DATABASE,
l1.relation,
l1.page,
l1.tuple,
l1.virtualxid,
l1.transactionid,
l1.classid,
l1.objid,
l1.objsubid
)
IS NOT DISTINCT FROM
(
l2.locktype,
l2.DATABASE,
l2.relation,
l2.page,
l2.tuple,
l2.virtualxid,
l2.transactionid,
l2.classid,
l2.objid,
l2.objsubid
)
)
WHERE
NOT l1.granted
AND
l2.granted;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment