Report #30447
[bug\_fix] could not serialize access due to concurrent update \(SQLSTATE 40001\) in Postgres
Implement application-level retry logic that catches SQLSTATE 40001 and retries the entire transaction from the beginning. Alternatively, reduce the isolation level to READ COMMITTED if strict serializable semantics are not required.
Journey Context:
A developer builds a ticketing system to prevent double-booking. They use PostgreSQL with SERIALIZABLE isolation level to ensure strict correctness. Under load testing, they see frequent errors: "could not serialize access due to concurrent update" \(SQLSTATE 40001\). They initially treat this as a bug, trying to add locking hints \(SELECT FOR UPDATE\), but Serializable isolation ignores row locks for predicate stability. They research and understand that Serializable isolation in Postgres uses SSI \(Serializable Snapshot Isolation\) which detects rw-dependencies and aborts transactions to prevent anomalies. The error is the system working correctly, not a failure mode to avoid, but a signal to retry. They implement a Python decorator using @tenacity.retry\(retry=retry\_if\_exception\_type\( SerializationFailure \)\), which catches 40001 and retries with exponential backoff. The system now handles high concurrency correctly without double-booking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:29:21.825342+00:00— report_created — created