DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / What to Log

log_lock_waits

Logs long lock waits.

  • Default: off
  • Type: bool
  • Applies: Session (superuser)

In plain words

When a query has to wait for a lock held by someone else for longer than deadlock_timeout (1 second by default), PostgreSQL logs a line naming the waiting process and the holder, and another when the lock is finally acquired. It is the best tool for finding blocking problems after the fact.

For DBAs and operators

Real lines with deadlock_timeout = 200ms (18.6):

LOG: process 4733 still waiting for RowExclusiveLock on relation 16384 of database 5 after 200.095 ms at character 8 DETAIL: Process holding the lock: 4731. Wait queue: 4733. STATEMENT: update t set v='x' where id=5 LOG: process 4733 acquired RowExclusiveLock on relation 16384 of database 5 after 1238.556 ms at character 8

The report is produced by the deadlock check that runs after deadlock_timeout, so lowering deadlock_timeout makes reports appear sooner (and runs deadlock checks more often). Waits for row locks show up as ShareLock on transaction N; waits for a relation show the relation OID (SELECT 16384::regclass in that database).

Cheap and highly recommended for production. Typical finding: an ALTER TABLE queued behind a long transaction, with every following query queued behind the ALTER. In the report, the long "Wait queue" shows that pile-up. See also log_lock_failures (PG18).

How to change it

A superuser (or a role granted SET) can change it per session with SET.

See it in context

Locking and deadlocks

Related parameters

deadlock_timeout log_lock_failures lock_timeout log_recovery_conflict_waits

All Reporting and Logging parameters