pg_locks
The view pg_locks provides access to information about the locks held by active processes within the database server. See Chapter 13 for more discussion of locking. pg_locks contains one row per active lockable object, requested lock mode, and relevant process. Thus, the same lockable object might appear many times, if multiple processes are holding or waiting for locks on it. However, an object that currently has no locks on it will not appear at all. There are several distinct types of lockable objects: whole relations (e.g., tables), individual pages of relations, individual tuples of relations, transaction IDs (both virtual and permanent IDs), and general database objects (identified by class OID and object OID, in the same way as in pg_description or pg_depend). Also, the right to extend a relation is represented as a separate lockable object, as is the right to update pg_database.datfrozenxid. Also, “advisory” locks can be taken on numbers that have user-defined meanings.
English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- kind
- view
- lang
- en
- measured attributes
- true
- metadata release
- 18.6
- runtime columns
- locktype, database, relation, page, tuple, virtualxid, transactionid, classid, objid, objsubid, virtualtransaction, pid, mode, granted, fastpath, waitstart
- runtime verified
- false
- source
- english-manual
Definition PG 18
The view pg_locks provides access to information about the locks held by active processes within the database server. See Chapter 13 for more discussion of locking. pg_locks contains one row per active lockable object, requested lock mode, and relevant process. Thus, the same lockable object might appear many times, if multiple processes are holding or waiting for locks on it. However, an object that currently has no locks on it will not appear at all. There are several distinct types of lockable objects: whole relations (e.g., tables), individual pages of relations, individual tuples of relations, transaction IDs (both virtual and permanent IDs), and general database objects (identified by class OID and object OID, in the same way as in pg_description or pg_depend). Also, the right to extend a relation is represented as a separate lockable object, as is the right to update pg_database.datfrozenxid. Also, “advisory” locks can be taken on numbers that have user-defined meanings.
Catalog columns
| Column | Type | Nullability | Description |
|---|---|---|---|
| locktype | text | Nullable | Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 27.11.) |
| database | oid | Nullable | OID of the database in which the lock target exists, or zero if the target is a shared object, or null if the target is a transaction ID |
| relation | oid | Nullable | OID of the relation targeted by the lock, or null if the target is not a relation or part of a relation |
| page | int4 | Nullable | Page number targeted by the lock within the relation, or null if the target is not a relation page or tuple |
| tuple | int2 | Nullable | Tuple number targeted by the lock within the page, or null if the target is not a tuple |
| virtualxid | text | Nullable | Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 67 |
| transactionid | xid | Nullable | ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 67 |
| classid | oid | Nullable | OID of the system catalog containing the lock target, or null if the target is not a general database object |
| objid | oid | Nullable | OID of the lock target within its system catalog, or null if the target is not a general database object |
| objsubid | int2 | Nullable | Column number targeted by the lock (the classid and objid refer to the table itself), or zero if the target is some other general database object, or null if the target is not a general database object |
| virtualtransaction | text | Nullable | Virtual ID of the transaction that is holding or awaiting this lock |
| pid | int4 | Nullable | Process ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transaction |
| mode | text | Nullable | Name of the lock mode held or desired by this process (see Section 13.3.1 and Section 13.2.3) |
| granted | bool | Nullable | True if lock is held, false if lock is awaited |
| fastpath | bool | Nullable | True if lock was taken via fast path, false if taken via main lock table |
| waitstart | timestamptz | Nullable | Time when the server process started waiting for this lock, or null if the lock is held. Note that this can be null for a very short period of time after the wait started even though granted is false. |
Compare versions
Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · catalog-bilingual-repair:5a3c2d53c37ad9893f445ecc9a9fcbc573749f093b400185fb781d7a7df0f1c4
Text language: en · catalog-bilingual-repair:5a3c2d53c37ad9893f445ecc9a9fcbc573749f093b400185fb781d7a7df0f1c4