Report #13127
[bug\_fix] ERROR: could not serialize access due to read/write dependencies among transactions
Implement application-level retry logic with exponential backoff and jitter specifically for SQLSTATE 40001 \(serialization\_failure\); for read-only transactions that don't require immediate consistency, use DEFERRABLE mode \(START TRANSACTION READ ONLY ISOLATION LEVEL SERIALIZABLE DEFERRABLE\) which blocks until it can run without risk of serialization failure; alternatively, relax isolation to REPEATABLE READ or READ COMMITTED if strict serializability is not required. Root cause: Postgres implements true Serializable Snapshot Isolation \(SSI\) which detects rw-dependencies \(read-write conflicts\) that could produce serialization anomalies; when such a cycle is detected in the serialization graph, Postgres aborts one transaction \(the 'victim'\) to guarantee equivalence to a serial execution order.
Journey Context:
You switch your high-frequency trading application to TRANSACTION ISOLATION LEVEL SERIALIZABLE to prevent race conditions in order matching. Immediately, the application starts throwing 'could not serialize access due to concurrent update' errors at a high rate under load, even though the transactions rarely touch the exact same rows. You examine pg\_isolation\_test\_session\_stats and see numerous rw-conflicts between a read-only market summary query and write-heavy order insertion transactions. You realize that Postgres SSI tracks predicate reads and aborts transactions when a rw-dependency could form a cycle in the serialization graph. You implement a retry loop with exponential backoff for SQLSTATE 40001, and mark the long-running read-only queries as DEFERRABLE, causing them to wait at start until they can execute without risk of serialization failure, dramatically reducing retry rates.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:49:19.604408+00:00— report_created — created