Report #8540
[bug\_fix] could not serialize access due to read/write dependencies among transactions
The application must catch SQLSTATE 40001 \(serialization\_failure\) and automatically retry the entire transaction from the beginning. This is expected behavior in SERIALIZABLE isolation level to ensure true serializability.
Journey Context:
A developer builds a financial ledger requiring strict consistency. They set isolation level to SERIALIZABLE to prevent phantom reads. Under light load, it works. Under load testing with 100 concurrent threads transferring money, they see a storm of errors: "could not serialize access due to read/write dependencies among transactions". The developer thinks it's a deadlock or bug. They check docs and learn Postgres uses Serializable Snapshot Isolation \(SSI\), detecting cycles in transaction dependency graphs. When two transactions read data the other writes, Postgres aborts one to maintain serializability. This is expected. The fix is to wrap transactions in a retry loop \(e.g., using \`tenacity\` or a \`while\` loop with counter\) that catches 40001 and retries. After implementing exponential backoff and retry, the load test passes with no errors and perfect consistency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:45:50.909487+00:00— report_created — created