Updated on 2024-12-18 GMT+08:00

PG_LWLOCKS

PG_LWLOCKS provides information on lightweight locks currently held or being waited for by the current instance. This view is supported only by 9.1.0.200 and later cluster versions.

Table 1 PG_LWLOCKS columns

Name

Type

Description

pid

bigint

ID of the backend thread.

query_id

bigint

ID of a query.

lwtid

integer

Lightweight thread ID of the backend thread.

reqlockid

integer

ID of the lightweight lock that is being requested by the current thread.

reqlock

text

Name of the lightweight lock corresponding to reqlockid.

heldlocknums

integer

Number of lightweight locks obtained by the current thread.

heldlockid

integer

Lightweight lock ID obtained by the current thread.

heldlock

text

Name of the lightweight lock corresponding to heldlockid.

heldlockmode

text

Lightweight lock mode corresponding to heldlockid.

Example

Use the PG_LWLOCKS view to query information about lightweight locks that are being held or waiting for the current instance.
1
2
3
4
5
6
SELECT * FROM pg_lwlocks;
       pid       |     query_id      | lwtid | reqlockid | reqlock | heldlocknums | heldlockid |      heldlock      | heldlockmode
-----------------+-------------------+-------+-----------+---------+--------------+------------+--------------------+--------------
 139810224192480 |                 0 | 54842 |           |         |            1 |          7 | WALWriteLock       | Exclusive
 139810224199520 | 78250043526306022 | 54963 |           |         |            1 |     193860 | BUFFER_POOL_LWLOCK | Exclusive
(2 rows)