↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / System Catalogs

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

ColumnTypeNullabilityDescription
locktypetextNullableType of the lockable object: relation, extend, frozenid, page, tuple, transactionid, virtualxid, spectoken, object, userlock, advisory, or applytransaction. (See also Table 27.11.)
databaseoidNullableOID 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
relationoidNullableOID of the relation targeted by the lock, or null if the target is not a relation or part of a relation
pageint4NullablePage number targeted by the lock within the relation, or null if the target is not a relation page or tuple
tupleint2NullableTuple number targeted by the lock within the page, or null if the target is not a tuple
virtualxidtextNullableVirtual ID of the transaction targeted by the lock, or null if the target is not a virtual transaction ID; see Chapter 67
transactionidxidNullableID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 67
classidoidNullableOID of the system catalog containing the lock target, or null if the target is not a general database object
objidoidNullableOID of the lock target within its system catalog, or null if the target is not a general database object
objsubidint2NullableColumn 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
virtualtransactiontextNullableVirtual ID of the transaction that is holding or awaiting this lock
pidint4NullableProcess ID of the server process holding or awaiting this lock, or null if the lock is held by a prepared transaction
modetextNullableName of the lock mode held or desired by this process (see Section 13.3.1 and Section 13.2.3)
grantedboolNullableTrue if lock is held, false if lock is awaited
fastpathboolNullableTrue if lock was taken via fast path, false if taken via main lock table
waitstarttimestamptzNullableTime 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