Symptoms
A requested lock could not be obtained (NOWAIT or lock_timeout).
- The error is written to the server log and returned to the client carrying
SQLSTATE 55P03. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
- PL/pgSQL can trap it by name:
EXCEPTION WHEN lock_not_available THEN.
Environment
Severity: ERROR | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).
Root Cause
The statement used NOWAIT or hit lock_timeout while another session held the lock.
Diagnostic Queries
Recovery
Steps to resolve 55P03:
- Retry with backoff; reduce contention and shorten transactions.
- Identify the blocker:
SELECT * FROM pg_locks JOIN pg_stat_activity USING (pid) WHERE NOT granted;. - For DDL, set a short
lock_timeoutand retry so you do not build a long blocking queue.
Reference: PostgreSQL error codes — Class 55 (Object Not In Prerequisite State).
Thanks — noted. This helps keep the database accurate.