PostgreSQL Error 55P03: Lock Not Available

PostgreSQL error 55P03 (Lock Not Available) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

SQLSTATE 55P03 PostgreSQL Last verified 2026-08-19

Quick Answer

Catch the error and either retry after a short wait or skip the row. If that does not apply, drop NOWAIT and use FOR UPDATE with a lock_timeout instead — the full checklist is below.

Error Code

SQLSTATE: 55P03
Official name: Lock Not Available
Service: PostgreSQL

What does this error mean?

A lock requested with the NOWAIT option could not be acquired immediately and the statement was aborted.

Common Causes

How to Fix

  1. Catch the error and either retry after a short wait or skip the row
  2. Drop NOWAIT and use FOR UPDATE with a lock_timeout instead
  3. Use SKIP LOCKED to process only currently-unlocked rows (queue pattern)
  4. Reduce the duration other transactions hold conflicting locks

Code Examples

Skip locked rows for a job queue sql
SELECT id FROM jobs WHERE status='pending'
ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 1;

SKIP LOCKED skips rows already locked, returning only available work — ideal for concurrent workers without triggering 55P03.

Framework-Specific Fixes

sqlalchemy

Use with_for_update(nowait=False, skip_locked=True) on a query to avoid 55P03.

row = session.query(Task).filter_by(status='pending')\
    .with_for_update(skip_locked=True).first()
supabase

Use an RPC that performs SELECT ... FOR UPDATE SKIP LOCKED for queue-style claims.

CREATE FUNCTION claim_task() RETURNS void AS $$
  UPDATE tasks SET status='running'
  WHERE id IN (SELECT id FROM tasks WHERE status='pending' FOR UPDATE SKIP LOCKED LIMIT 1)
$$ LANGUAGE sql;

You Might Also Like

Frequently Asked Questions

Why am I seeing PostgreSQL error 55P03?

Most often this happens when sELECT ... FOR UPDATE NOWAIT hits a row already locked by another transaction, or when lOCK TABLE ... NOWAIT on a table with an active conflicting lock.

How do I fix PostgreSQL error 55P03?

Catch the error and either retry after a short wait or skip the row.

Which frameworks have documented fixes for error 55P03?

This page documents fixes for: sqlalchemy, supabase.

Official Sources

This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.