Isolation Levels & Anomalies in SQL
Which anomaly each level forbids — and the retry price
READ COMMITTED (PG default): no dirty reads; statement snapshots. REPEATABLE READ: transaction snapshot — no non-repeatables (PG snapshot isolation). SERIALIZABLE: serial-equivalence, aborts on conflicts — apps retry. Anomalies: dirty (uncommitted visible), non-repeatable (re-read changed), phantom (range recount gains rows). Higher costs concurrency + retries.
Dirty never on PG
No READ UNCOMMITTED effect — uncommitted invisible always.
Non-repeatable vs phantom
Re-read changed row vs range recount gains rows — different anomalies.
Levels ladder up
COMMITTED → REPEATABLE (snapshot) → SERIALIZABLE (serial + retry).
Lowest that forbids
Default COMMITTED; snapshot reports; serializable money with retries.
1-- PostgreSQL:2BEGIN ISOLATION LEVEL REPEATABLE READ;
| level | guarantee |
|---|---|
| READ COMMITTED | no dirty; default |
| REPEATABLE READ | snapshot-stable |
| SERIALIZABLE | serial + retry |
Report re-reads the same range twice — REPEATABLE freezes the view; READ COMMITTED could show new rows (phantom). SERIALIZABLE would additionally abort conflicting writers.
Phantom in range recount
Second count sees new commits below serializable.
1-- txn A counts twice; txn B inserts + commits between2-- READ COMMITTED: 41 then 42 (phantom)
| read | rows |
|---|---|
| first count | 41 |
| second count | 42 |
Serializable + retry loop
Abort is expected, not exceptional.
1-- on 40001 / deadlock: ROLLBACK whole txn, refetch, retry with backoff
| signal | action |
|---|---|
| abort rate | retry with backoff |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.