ERROR: could not serialize access due to concurrent update

A REPEATABLE READ/SERIALIZABLE transaction conflicted with a concurrent one and must be retried.

Seen on: PostgreSQL

Meaning

Higher isolation levels detect conflicts instead of blocking; the application is expected to retry the whole transaction.

Common causes

  • Concurrent updates to the same rows under REPEATABLE READ/SERIALIZABLE
  • Hot rows (counters) updated by many transactions

⚡ Quick fix

  1. Retry the transaction on SQLSTATE 40001
  2. Reduce contention on hot rows
  3. Use READ COMMITTED with explicit locks if appropriate

Detailed fix by platform

PostgreSQL

  1. Wrap the transaction in a retry loop (3–5 attempts with small backoff)

How to diagnose

  1. Isolation — Which level?
  2. Rows — What is contended?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.