Skip to content

Instantly share code, notes, and snippets.

@redsfyre
Created March 20, 2024 19:29
Show Gist options
  • Save redsfyre/819ddf0447e81d375d6e4245e9c96057 to your computer and use it in GitHub Desktop.
Save redsfyre/819ddf0447e81d375d6e4245e9c96057 to your computer and use it in GitHub Desktop.
Postgresql locks view
CREATE OR REPLACE VIEW public.active_locks AS
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment