Incident Brief
What happened: A transaction running under SERIALIZABLE isolation is rolled back – usually at COMMIT – even though every statement in it was valid and no constraint was violated:
ERROR: 40001: could not serialize access due to read/write dependencies among transactions
DETAIL: Reason code: Canceled on identific
Immediate action: 1. Read the HINT – "The transaction might succeed if retried." That is the supported remedy.
2. Roll back the aborted transaction (it is already aborted; issue ROLLBACK to end it cleanly).
3. Re-run t
The fix
- Read the HINT - "The transaction might succeed if retried." That is the supported remedy.
- Roll back the aborted transaction (it is already aborted; issue ROLLBACK to end it cleanly).
- Re-run the ENTIRE transaction from the beginning. Replaying only the failed statement is wrong - the snapshot is gone.
- Wrap the transaction in a bounded retry loop with exponential backoff + jitter, catching SQLSTATE
40001(and40P01deadlock_detected, which is handled the same way). On a fresh attempt t
Reproduce & verify
What you see
A transaction running under SERIALIZABLE isolation is rolled back - usually at COMMIT - even though every statement in it was valid and no constraint was violated:
ERROR: 40001: could not serialize access due to read/write dependencies among transactions
DETAIL: Reason code: Canceled on identificConfirm it yourself
Confirm it really is SSI (read/write dependency) and not the REPEATABLE READ "concurrent update" variant.
-- 1) What isolation level is the failing transaction using? It must be SERIALIZABLE for THIS message:
SHOW default_transaction_isolation;
-- inside the transaction:
SELECT current_setting('transaction_isolation');-- 2) Reproduce deterministically with two sessions, A and B, on a small table:
-- (session A) (session B)
-- BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
--Prevent it everywhere
PROStop this error from ever shipping again
The steps above clear the error in front of you. Pro adds the executed depth that finds every latent occurrence across your schema, views and CI — before it pages anyone.
Free — what you just got
- The copy-paste fix
- Why it happens
- Reproduced on real PostgreSQL
- No fleet-wide audit
- No prevention tooling
Pro — never again
- Catalog audit — one query that flags every view & function carrying the same latent fault
- Prevention tooling — a CI check + regression test that fails the build, not production
- Cloud variants — exact behaviour on RDS, Azure & Cloud SQL
- Every error page, unlocked