SQLSTATE 40001Severity highLab verified

Incident brief

Could not serialize access due to concurrent update

The REPEATABLE READ concurrent-update form of SQLSTATE 40001: a REPEATABLE READ transaction attempted to update a row that a concurrently committed transaction had already changed. This page scopes to that exact form — the one reproduced in the lab below, not the general SERIALIZABLE case.

Reproduced on PostgreSQL 16.14Verified 2026-07-14 (Docker lab, PostgreSQL 16.14)Reviewed by Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What
Could not serialize access due to concurrent update
What triggers it
Open session A and start a REPEATABLE READ transaction.
The fix
Rollback and retry the unit of work.
Proof
Reproduced on PostgreSQL 16.14 → Session A's transaction was cancelled and rolled back — no data change from session A. Session B's update had already committed successfully before session A's failure.

The fix

What to do right now

The immediate, application-level response to this error.

  • Rollback and retry the unit of work.
  • Apply exponential backoff in the application layer.
  • Shorten the transaction so contention windows shrink.
Fix — SQL
-- application strategy
BEGIN ISOLATION LEVEL REPEATABLE READ;
UPDATE accounts SET balance = balance + 100 WHERE id = 1;
COMMIT;
-- if this raises 40001: ROLLBACK, then retry the whole transaction
-- from the beginning with bounded exponential backoff

Verification

PG 16.14
Last verified
2026-07-14 (Docker lab, PostgreSQL 16.14)
Reviewed by
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed