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):
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
Related parameters
deadlock_timeout log_lock_failures lock_timeout log_recovery_conflict_waits