PostgreSQL lock_not_available
A statement configured not to wait, or constrained by lock_timeout, could not acquire its required lock.
ERROR: could not obtain lock on relationAlso searched as: lock_not_available · canceling statement due to lock timeout
What it means
Another transaction currently holds an incompatible lock. The error prevents indefinite waiting but does not identify whether the blocker is healthy, stuck, or part of expected concurrent work.
Typical trigger conditions
- DDL during active transactions
- SELECT ... FOR UPDATE NOWAIT contention
- A low lock_timeout
- Long-running or idle-in-transaction sessions
First diagnostic checks
Find blocking process IDs
Map waiting sessions to the sessions that block them.
SELECT pid, pg_blocking_pids(pid), wait_event_type, wait_event, query FROM pg_stat_activity WHERE wait_event_type = 'Lock';
Inspect blocker age
Confirm transaction start time and state before considering cancellation.
Review timeout intent
Keep bounded waits, but align lock_timeout with the operation and retry strategy.
Version and platform notes
Available wait-event detail has expanded over PostgreSQL releases; the SQLSTATE remains stable.
Follow PostgreSQL failures and fixes
One useful weekly email with new error references, tools, integration notes and production lessons. No daily noise.