Report #59793
[bug\_fix] ERROR: could not serialize access due to concurrent update \(Postgres SSI conflict\)
Implement explicit application-level retry logic specifically for SQLSTATE 40001 \(serialization\_failure\). Use exponential backoff between retries and ensure transactions are idempotent.
Journey Context:
A financial ledger application using SERIALIZABLE isolation level to prevent phantom reads during account transfers started throwing 'could not serialize access due to read/write dependencies' errors under load. Initially confused with deadlock errors, but noted the SQLSTATE was 40001 not 40P01. Researching Postgres docs revealed that Serializable Snapshot Isolation \(SSI\) detects rw-conflicts: when Transaction A reads a row that Transaction B subsequently modifies, and A then tries to write \(or commit\), creating a dangerous structure that could violate serializability. Unlike deadlocks which are immediate cycles, these are dependency conflicts. The debugging involved setting log\_line\_prefix to include transaction IDs and analyzing the logs for 'could not serialize' patterns. The application code was wrapping balance checks and updates in SERIALIZABLE transactions, but under concurrent load, two transfers reading the same account balance would trigger the conflict. The fix required implementing a specific retry mechanism in the application's database wrapper: catch SQLSTATE 40001, wait with exponential jitter \(e.g., 2^attempts \* random\), then retry the entire transaction. This is expected behavior for SSI, not a bug.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:51:11.335435+00:00— report_created — created