Skip to content
← Catalog atlas / pg_locks

SYSTEM VIEW · System view

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.

First seen PG 9.0Last seen PG 19Columns 16

Checked column by column against a PostgreSQL 18.6 instance · Raw measurement record ↗

Columns PostgreSQL 18

pg_locks
COLUMNTYPEDESCRIPTION
locktype text 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 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 IDReferences:pg_database.oid
relation oid OID of the relation targeted by the lock, or null if the target is not a relation or part of a relationReferences:pg_class.oid
page integerDocumented as:int4 Page number targeted by the lock within the relation, or null if the target is not a relation page or tuple
tuple smallintDocumented as: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 Chapter 67
transactionid xid ID of the transaction targeted by the lock, or null if the target is not a transaction ID; Chapter 67
classid oid OID of the system catalog containing the lock target, or null if the target is not a general database objectReferences:pg_class.oid
objid oid OID of the lock target within its system catalog, or null if the target is not a general database objectReferences:any OID column
objsubid smallintDocumented as: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 integerDocumented as: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 Section 13.3.1 and Section 13.2.3)
granted booleanDocumented as:bool True if lock is held, false if lock is awaited
fastpath booleanDocumented as:bool True if lock was taken via fast path, false if taken via main lock table
waitstart timestamp with time zoneDocumented as: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.

Columns marked "implicit" are not included in SELECT *; some early statistics views are completed from same-version source, and the extra provenance is shown in the column description.

Column evolution matrix

Hover a cell for the column type
PresentAdded / type or attribute changeRemoved
COLUMN9.09.19.29.39.49.59.610111213141516171819
locktype
database
relation
page
tuple
virtualxid
transactionid
classid
objid
objsubid
virtualtransaction
pid
mode
granted
fastpath
waitstart

9.0 is the coverage baseline; a column already present in the baseline is not marked as added. The matrix aligns columns by name, so a rename appears as the old column removed and a new column added.

Evolution timeline

Changes between adjacent majors

PostgreSQL 18 ← 17

2 column description updates

PostgreSQL 17 ← 16

3 column description updates

PostgreSQL 16 ← 15

3 column description updates

PostgreSQL 14 ← 13

+ waitstart1 column description updates

PostgreSQL 13 ← 12

1 column description updates

PostgreSQL 10 ← 9.6

Catalog description updated

PostgreSQL 9.6 ← 9.5

Catalog description updated

PostgreSQL 9.5 ← 9.4

1 column description updatesCatalog description updated

PostgreSQL 9.2 ← 9.1

+ fastpath8 column description updates

PostgreSQL 9.1 ← 9.0

3 column description updatesCatalog description updated

Compare any two versions

Pick two versions to see added, removed, and retyped columns. The interactive comparison needs JavaScript; the evolution timeline reads fine without it.