Report #50844
[bug\_fix] ERROR: could not serialize access due to concurrent update \(SQLSTATE 40001\) under SERIALIZABLE isolation
Implement a retry loop in the application code that catches SQLSTATE 40001 \(serialization\_failure\) and retries the entire transaction from the beginning with exponential backoff. This is expected behavior for Serializable Snapshot Isolation \(SSI\) and not an error to be suppressed.
Journey Context:
Application uses SERIALIZABLE isolation level to ensure strict correctness for financial transfers. Under load, it throws ERROR: could not serialize access due to concurrent update. The developer initially thinks it's a bug because the queries are correct and conflicts should be handled. Investigation reveals that PostgreSQL's Serializable Snapshot Isolation \(SSI\) detects rw-dependencies that could lead to anomalies and aborts one transaction to preserve serializability. The rabbit hole involves understanding that this is expected behavior for SSI, not a failure mode. The application must be designed to handle 40001 errors by retrying. Without this, the app fails under any concurrent write to related data, making SSI unusable without retry logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:49:39.930590+00:00— report_created — created