Skip to content

Instantly share code, notes, and snippets.

@thomas-maschler
Created March 17, 2017 20:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomas-maschler/bb9fb8d028f84b754c276bd775a06c5a to your computer and use it in GitHub Desktop.
Save thomas-maschler/bb9fb8d028f84b754c276bd775a06c5a to your computer and use it in GitHub Desktop.
Remove locks from Postgres tables
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
WHERE t.schemaname <> 'pg_toast'::name 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