Skip to content

Instantly share code, notes, and snippets.

@fljdin
Last active November 21, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fljdin/ba29a78f6456cf3e6782baa94cf7e3f8 to your computer and use it in GitHub Desktop.
Save fljdin/ba29a78f6456cf3e6782baa94cf7e3f8 to your computer and use it in GitHub Desktop.
Detect blocked and blocking sessions in PostgreSQL 9.6+
SELECT pid, state,
CASE WHEN wait_event is not null
THEN concat(wait_event, ' (', wait_event_type, ')')
ELSE NULL::text END AS lock_intel,
pg_blocking_pids(pid) AS blocked_by,
substr(query, 1, 20)
FROM pg_stat_activity
WHERE state IS NOT NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment