Skip to content

Instantly share code, notes, and snippets.

@isaaclw
Last active June 23, 2020 15:54
Show Gist options
  • Save isaaclw/284c16f375a168a13fcd12706c812a05 to your computer and use it in GitHub Desktop.
Save isaaclw/284c16f375a168a13fcd12706c812a05 to your computer and use it in GitHub Desktop.
pg blocking queries #psql #db #postgres #sql
SELECT blocks.pid,
(select query from pg_stat_activity where pid = blocks.pid) as blocked_query,
blocks.blocking_pid,
(select query from pg_stat_activity where pid = blocks.blocking_pid) AS blocking_query
FROM (
SELECT pid, unnest(pg_blocking_pids(pid)) AS blocking_pid
FROM pg_locks
WHERE granted = false
) AS blocks;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment