Parameter · Reporting and Logging / What to Log
log_lock_failures
Logs lock failures.
- Default:
off - Type: bool
- Applies: Session (superuser)
In plain words
When a query asks for a lock with NOWAIT and the lock is busy, it fails immediately with an error. With this setting on, PostgreSQL also logs which process held the lock, so you can find out who was in the way.
For DBAs and operators
New in PostgreSQL 18. Currently it covers only row locks requested with NOWAIT (SELECT … FOR UPDATE/SHARE NOWAIT); it does not log LOCK TABLE … NOWAIT, lock_timeout or SKIP LOCKED (verified on 18.6: those produced only the usual ERROR, or nothing). Captured on 18.6:
Note the row lock shows up as a lock on the holder's transaction (row locks wait for the locking transaction to end). Use the holder PID with pg_stat_activity to see what it is doing, if it is still there. Superuser-settable per session, so you can enable it just for the job that uses NOWAIT. For lock waits (as opposed to failures) see log_lock_waits.
How to change it
A superuser (or a role granted SET) can change it per session with SET.