Last active
December 9, 2022 20:05
-
-
Save marcomalva/4bde465257f6d06ed6da71ebc5cf8d66 to your computer and use it in GitHub Desktop.
[PostgreSQL - List Locks]List database locks w SQL #psql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- list databse locks hold by SQL statements for current DB instance, source: <https://wiki.postgresql.org/wiki/Lock_Monitoring> | |
SELECT a.datname, | |
l.relation::regclass, | |
l.transactionid, | |
l.mode, | |
l.GRANTED, | |
a.usename, | |
a.query, | |
a.query_start, | |
age(now(), a.query_start) AS "age", | |
a.pid | |
FROM pg_stat_activity a | |
JOIN pg_locks l ON l.pid = a.pid | |
WHERE datname = current_database() | |
ORDER BY a.query_start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment