Cookbook recipe

Serialization failures and retry logic

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

Under SERIALIZABLE (or REPEATABLE READ) transactions fail with "could not serialize access". This is expected — handle it with retries. Diagnose it Identify the SQLSTATE so you can catch it: -- 40001 serialization_failure -- 40P01 deadlock_detected…

Investigation Path

Under SERIALIZABLE (or REPEATABLE READ) transactions fail with “could not serialize access”. This is expected — handle it with retries.

Diagnose it

Identify the SQLSTATE so you can catch it:

-- 40001 serialization_failure
-- 40P01 deadlock_detected
-- both are safe to retry

Why it happens

Serializable Snapshot Isolation detects when concurrent transactions would produce a non-serializable result and aborts one. It guarantees correctness without locking everything, at the cost of occasional retries.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes