Skip to content

Instantly share code, notes, and snippets.

@sbaltus
Last active January 18, 2018 15:59
Show Gist options
  • Select an option

  • Save sbaltus/36ec93a4631a6ae1208558a205d0cd67 to your computer and use it in GitHub Desktop.

Select an option

Save sbaltus/36ec93a4631a6ae1208558a205d0cd67 to your computer and use it in GitHub Desktop.
Useful administration queries
-- Lock management
https://wiki.postgresql.org/wiki/Lock_Monitoring
SELECT relname,
mode,
relation,
database,
pid,
query
FROM pg_locks
INNER JOIN pg_stat_activity using(pid)
INNER JOIN pg_class on pg_locks.relation = pg_class.oid;
SELECT relation::regclass, * FROM pg_locks WHERE NOT GRANTED;
-- Kill specific PID
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE pid <> pg_backend_pid()
AND datname = 'yourdbname' -- or any other condition, based on pg_stat_activity fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment