-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathpostgres_locks_query_age.sql
More file actions
42 lines (39 loc) · 904 Bytes
/
postgres_locks_query_age.sql
File metadata and controls
42 lines (39 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--
-- Author: Hari Sekhon
-- Date: 2020-08-07 00:47:45 +0100 (Fri, 07 Aug 2020)
--
-- vim:ts=4:sts=4:sw=4:et:filetype=sql
--
-- https://github.com/HariSekhon/SQL-scripts
--
-- License: see accompanying Hari Sekhon LICENSE file
--
-- If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
--
-- https://www.linkedin.com/in/HariSekhon
--
-- PostgreSQL locks with query and age
--
-- Requires PostgreSQL 9.2+
--
-- Tested on PostgreSQL 9.2+, 10.x, 11.x, 12.x, 13.0
-- 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
ORDER BY
a.query_start;