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
- Retry the transaction on 40001 — this is expected under SERIALIZABLE.
- Keep serializable transactions short and touch fewer rows.
- Consider
REPEATABLE READif SSI guarantees are stronger than you need.
Related & next steps
Reference: PostgreSQL 18 Section 13.2 “Transaction Isolation”.
Thanks — noted. This helps keep the database accurate.