Report #86979
[bug\_fix] ERROR: could not serialize access due to concurrent update
When using REPEATABLE READ or SERIALIZABLE, catch serialization\_failure / 40001 and retry the entire transaction from the beginning. Alternatively, switch to READ COMMITTED and use SELECT FOR UPDATE or an atomic UPSERT \(INSERT ... ON CONFLICT\) to eliminate read-modify-write races.
Journey Context:
A Python worker running at REPEATABLE READ reads an account balance, checks it, and then updates the row. Under concurrency another transaction updates the same row first; Postgres aborts the first transaction with 'could not serialize access due to concurrent update' to preserve the isolation guarantee. The developer initially lowers the isolation level blindly and sees lost-update anomalies. The correct fix is to retry the whole transaction on serialization failures, or to lock the row with SELECT FOR UPDATE under READ COMMITTED, because Postgres only raises this error when it cannot produce a result equivalent to some serial order.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:34:52.564285+00:00— report_created — created