pg_locks — PostgreSQL system view

The PostgreSQL pg_locks system view: full column reference (names, types, descriptions), catalog relationships and version support.

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):

  • locktype text
    Type of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also wait_event_lock_table.)
  • database oid references pg_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 ID
  • relation oid references pg_class.oid
    OID of the relation targeted by the lock, or null if the target is not a relation or part of a relation
  • page int4
    Page number targeted by the lock within the relation, or null if the target is not a relation page or tuple
  • tuple int2
    Tuple number targeted by the lock within the page, or null if the target is not a tuple
  • virtualxid text
    Virtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see transactions
  • transactionid xid
    ID of the transaction targeted by the lock, or null if the target is not a transaction ID; transactions
  • classid oid references pg_class.oid
    OID of the system catalog containing the lock target, or null if the target is not a general database object
  • objid oid references any OID column
    OID of the lock target within its system catalog, or null if the target is not a general database object
  • objsubid int2
    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
    Virtual ID of the transaction that is holding or awaiting this lock
  • pid int4
    Process ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transaction
  • mode text
    Name of the lock mode held or desired by this process (see locking_tables and xact_serializable)
  • granted bool
    True if lock is held, false if lock is awaited
  • fastpath bool
    True if lock was taken via fast path, false if taken via main lock table
  • waitstart timestamptz
    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:

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.