Summary
The view pg_locks provides access to information about the locks held by active processes within the database server. See mvcc for more discussion of locking.
(Description quoted from the official PostgreSQL documentation.)
Columns
The pg_locks system view exposes the following columns (names, types and descriptions are taken verbatim from the PostgreSQL documentation):
locktypetext
Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also wait_event_lock_table.)databaseoidreferencespg_database.oid
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 IDrelationoidreferencespg_class.oid
OID of the relation targeted by the lock, or null if the target is not a relation or part of a relationpageint4
Page number targeted by the lock within the relation, or null if the target is not a relation page or tupletupleint2
Tuple number targeted by the lock within the page, or null if the target is not a tuplevirtualxidtext
Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see transactionstransactionidxid
ID of the transaction targeted by the lock, or null if the target is not a transaction ID; transactionsclassidoidreferencespg_class.oid
OID of the system catalog containing the lock target, or null if the target is not a general database objectobjidoidreferencesany OID column
OID of the lock target within its system catalog, or null if the target is not a general database objectobjsubidint2
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 objectvirtualtransactiontext
Virtual ID of the transaction that is holding or awaiting this lockpidint4
Process ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transactionmodetext
Name of the lock mode held or desired by this process (see locking_tables and xact_serializable)grantedbool
True if lock is held, false if lock is awaitedfastpathbool
True if lock was taken via fast path, false if taken via main lock tablewaitstarttimestamptz
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.
Related catalogs
This object references the following other system catalogs:
database→pg_databaserelation→pg_class
Version applicability
Present in PostgreSQL 17, 18, 19 (verified against each release’s documentation). This is a long-standing system object that also exists in earlier PostgreSQL releases.
Related & references
Reference: PostgreSQL documentation — pg_locks.