Skip to content

Instantly share code, notes, and snippets.

@ignavan39
Last active March 16, 2022 10:48
Show Gist options
  • Save ignavan39/15dbfa1c1396587958b389bd7f9179ef to your computer and use it in GitHub Desktop.
Save ignavan39/15dbfa1c1396587958b389bd7f9179ef to your computer and use it in GitHub Desktop.
Find and kill table locks
SELECT t.schemaname,
t.relname,
l.locktype,
l.page,
l.virtualtransaction,
l.pid,
l.mode,
l.granted
FROM pg_locks l
JOIN pg_stat_all_tables t ON l.relation = t.relid AND t.schemaname <> 'pg_catalog'::name
ORDER BY t.schemaname, t.relname;
SELECT pg_cancel_backend('%pid%');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment