Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Last active September 29, 2017 17:28
Show Gist options
  • Select an option

  • Save bitdivine/4047518bb2c48ae59a9262cf2f722cb4 to your computer and use it in GitHub Desktop.

Select an option

Save bitdivine/4047518bb2c48ae59a9262cf2f722cb4 to your computer and use it in GitHub Desktop.
View of the current table locks in postgres and the queries holding them.
CREATE VIEW inf_locks AS
SELECT locktype, relation::regclass, mode, transactionid AS tid,
virtualtransaction AS vtidi, usename, pid, granted, query
FROM pg_catalog.pg_locks l LEFT JOIN pg_catalog.pg_database db
ON db.oid = l.database left join pg_stat_activity using (pid) WHERE (db.datname = 'blue' OR db.datname IS NULL)
AND NOT pid = pg_backend_pid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment