View pg_active_locks
Creates a view to view all live locks with all necessary information about the connections and the query.
Columns
| Column Name | datatype | Description |
|---|---|---|
| application_name | text | The name of the application, could be empty if not set by a client. |
| client_address | inet | The clients IP address. |
| query_start | timestamp with time zone | The timestamp of the start of the query. |
| query_age | interval | How long the query is already running. |
| wait_event_type | text | The type of event for which the backend is waiting, if any; otherwise NULL, for details see WAIT EVENT TABLE. |
| wait_event | text | Wait event name if backend is currently waiting, otherwise NULL. For details see WAIT EVENT ACTIVITY TABLE and WAIT EVENT TIMEOUT TABLE |
| locktype | text | The type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction, see Wait Events of Type Lock. |
| mode | text | The name of the lock mode held or desired by this process. For details see TABLE LEVEL LOCKS and SERIALIZABLE ISOLATION LEVEL |
| query | text | This is the SQL source of the query. |
Example
SELECT *
FROM pg_active_locks;
Result:
| pid | state | database_name | rolename | application_name | client_address | query_start | query_age | wait_event_type | wait_event | locktype | mode | query |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 228633 | active | chinook | stefanie | DBeaver 25.1.3 | 127.0.0.1 | 2025-08-14 15:13:52.866 +0200 | -00:00:00.010365 | relation | AccessShareLock | SELECT DISTINCT pid, state, datname AS database_name, usename AS rolename, application_name, client_addr AS client_address, query_start, age (now(), a.query_start) AS query_age, wait_event_type, wait_event, locktype,mode , query FROM pg_stat_activity AS a INNER JOIN pg_locks AS l USING(pid) | ||
| 228633 | active | chinook | stefanie | DBeaver 25.1.3 | 127.0.0.1 | 2025-08-14 15:13:52.866 +0200 | -00:00:00.010365 | virtualxid | ExclusiveLock | SELECT DISTINCT pid, state, datname AS database_name, usename AS rolename, application_name, client_addr AS client_address, query_start, age (now(), a.query_start) AS query_age, wait_event_type, wait_event, locktype, mode, query FROM pg_stat_activity AS a INNER JOIN pg_locks AS l USING(pid) |