SQLSTATE 40001 ERROR Class 40: Transaction Rollback

serialization_failure could not serialize access due to read/write dependencies among transactions — 40001

PostgreSQL error "could not serialize access due to read/write dependencies among transactions" (SQLSTATE 40001): what it means, common causes, and how …

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

Under SERIALIZABLE isolation, PostgreSQL detected a dangerous read/write dependency cycle and aborted a transaction to preserve serializable correctness. It raises SQLSTATE 40001 (serialization_failure).

  • Only occurs under SERIALIZABLE isolation (SSI).
  • The transaction can usually succeed if simply retried.
  • A HINT recommends retrying the transaction.

What the server log shows

ERROR:  could not serialize access due to read/write dependencies among transactions
DETAIL:  Reason code: Canceled on identification as a pivot, during write.
HINT:  The transaction might succeed if retried.

Why PostgreSQL raises this — what the manual says

Section 13.2.3 Serializable Isolation Level:

“They are used to identify and flag dependencies among concurrent Serializable transactions which in certain combinations can lead to serialization anomalies.”

Serializable Snapshot Isolation tracks read/write dependencies between concurrent transactions. When it finds a cycle that could violate serializability, it cancels one transaction (the pivot) with 40001 so the committed outcome is still equivalent to some serial order.

Common causes

  • Concurrent SERIALIZABLE transactions with interleaving reads and writes.
  • High contention on overlapping data sets.
  • Long-running serializable transactions increasing conflict windows.

How to fix it

  1. Retry the transaction on 40001 — this is expected under SERIALIZABLE.
  2. Keep serializable transactions short and touch fewer rows.
  3. Consider REPEATABLE READ if SSI guarantees are stronger than you need.

Related & next steps

Reference: PostgreSQL 18 Section 13.2 “Transaction Isolation”.

Was this helpful?