skip to content

isolation levels: the standard vs postgres

READ UNCOMMITTED is READ COMMITTED, REPEATABLE READ is snapshot isolation. the table the standard doesn't show you.

address
everything.transactions.isolation_levels
part
part 11, transactions and isolation
chapter
chapter 4 of 11
reading time
8 min

the SQL standard defines four isolation levels by which anomalies each one must rule out. postgres accepts all four names but runs three: READ UNCOMMITTED is READ COMMITTED, REPEATABLE READ is snapshot isolation (stronger than the standard asks: no phantoms), and SERIALIZABLE really is serializable, by aborting a transaction when it has to.

the picture

you know the table every database course shows, four levels down the side and three anomalies across the top? that's the standard's table. it says what each level is allowed to let through, which is a floor, not a description. a database may do better, and postgres does, in two places.

think of building codes (the standard) and an actual house (postgres). the code says how strong a wall must be at least. it doesn't tell you how strong the wall is.

the standard, as the postgres manual describes it
leveldirty readnon-repeatable readphantomserialization anomaly
read uncommittedpossiblepossiblepossiblepossible
read committednopossiblepossiblepossible
repeatable readnonopossiblepossible
serializablenononono
postgres 18.6, one captured run per cell
leveldirty readnon-repeatable readphantomlost updateread skewwrite skew
read uncommittednohappenshappenshappenshappenshappens
read committednohappenshappenshappenshappenshappens
repeatable readnonono40001nohappens
serializablenonono40001no40001
it happenedprevented (40001: by aborting a transaction)
real output, a postgres 18.6 server · anomaly-*
the standard's table, as the postgres manual describes it, and postgres 18.6's, where every cell is a captured run (the same runs as the anomaly lab). hover a postgres cell for what the run showed. the differences: read uncommitted never reads dirty data, and repeatable read has no phantoms.

the standard doesn't mention lost updates, read skew or write skew at all. it defines the three lower levels by three phenomena, and SERIALIZABLE as "the same result as some one-at-a-time order". everything else is a serialization anomaly, which the standard only rules out at the top. so the postgres table has six columns where the standard's has four.

picking a level

per transaction, at BEGIN (or with SET TRANSACTION before the first query), or as the default for a session, a role or the whole server:

sqlempty db
SHOW default_transaction_isolation;
BEGIN ISOLATION LEVEL REPEATABLE READ;
SHOW transaction_isolation;
COMMIT;
SET default_transaction_isolation = 'serializable';
BEGIN;
SHOW transaction_isolation;
COMMIT;
output, from postgres 18.6
#1 · SHOW
default_transaction_isolationtext
read committed
(1 row)
#2 · BEGIN
#3 · SHOW
transaction_isolationtext
repeatable read
(1 row)
#4 · COMMIT
#5 · SET
#6 · BEGIN
#7 · SHOW
transaction_isolationtext
serializable
(1 row)
#8 · COMMIT

the level is fixed once the transaction has run a query. changing it after that is an error:

sqlempty db
BEGIN;
SELECT 1;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
output, from postgres 18.6
#1 · BEGIN
#2 · SELECT 1
?column?int4
1
(1 row)
#3 · ERROR 25001
ERROR 25001: SET TRANSACTION ISOLATION LEVEL must be called before any query

transaction aborted: ROLLBACK to continue

READ UNCOMMITTED is READ COMMITTED

postgres takes the name, reports it back, and runs the transaction exactly like READ COMMITTED. it can't do anything else: a dirty read would mean showing a row version written by a transaction that's still running, and no snapshot ever includes one. here T2 asks for it while T1 has an uncommitted withdrawal:

T1
snapshot 759:759:
T2
·
1
BEGIN

read uncommitted. T1 opens a transaction.

step 1/7
real output, a postgres 18.6 server · anomaly-dirty-read
T2's SHOW says read uncommitted. its read says 100.00, the committed balance, not T1's uncommitted 0.00.

REPEATABLE READ is snapshot isolation

one snapshot for the whole transaction, taken at its first statement (not at BEGIN), and every read comes from it. that gives you more than the standard's REPEATABLE READ: rows you've read can't change under you, and rows can't appear either, because a new row committed after your snapshot is simply not in it.

T2 runs at =
T1
·
T2
snapshot 761:761:
1
BEGIN ISOLATION LEVEL READ COMMITTED

read committed. T2 opens a transaction.

step 1/5
real output, a postgres 18.6 server · anomaly-phantom
the same count, twice, while T1 inserts carol's account. at read committed the second count is 3. at repeatable read it stays 2: no phantom, though the standard would allow one.
predict the output
T2 runs BEGIN ISOLATION LEVEL REPEATABLE READ. T1 then commits alice = 150.00. then T2 reads alice for the first time. what does it see?
sql
/* T2 */ BEGIN ISOLATION LEVEL REPEATABLE READ;
/* T1 */ UPDATE accounts SET balance = 150.00 WHERE id = 1;  -- commits
/* T2 */ SELECT balance FROM accounts WHERE id = 1;          -- ?
T1
·
T2
·
1
BEGIN ISOLATION LEVEL REPEATABLE READ

T2 begins a repeatable read transaction. no snapshot yet: BEGIN doesn't take one.

step 1/6
real output, a postgres 18.6 server · rr-first-statement
the run behind that predict. watch the snapshot under T2's name: there's none after BEGIN, and it's fixed from the first SELECT on.

snapshot isolation has two consequences you have to plan for. a write that would overwrite a row changed after your snapshot fails with 40001 instead of losing an update, so every writer at this level needs a retry loop. and it checks only for write-write conflicts on the same row, so write skew, two transactions writing different rows based on what the other one changed, gets through.

SERIALIZABLE is SERIALIZABLE

snapshot isolation plus a record of what every transaction read. when the reads and writes of overlapping transactions form a pattern that no one-at-a-time order could produce, postgres fails one of them with 40001, sometimes at COMMIT. the guarantee is the standard's: if each transaction is correct alone, the mix is correct. the price is the retries, and a little bookkeeping. serializable snapshot isolation is how it's built.

so which one?

leveleach statement seesstopsyou must handle
READ COMMITTED (default)everything committed before the statement begandirty readslost updates, read and write skew, in your own code
REPEATABLE READeverything committed before the transaction's first statementall but write skew40001 on write conflicts
SERIALIZABLEthe same snapshot, plus read trackingeverything40001, more often, possibly at COMMIT

short transactions that touch a few known rows: READ COMMITTED, with the arithmetic in the UPDATE. reports and exports that read a lot: REPEATABLE READ (one consistent moment, never fails a read-only transaction). anything that checks a rule across rows before writing: SERIALIZABLE everywhere, with a retry loop. and if you move between databases, check what the names mean there: mysql's InnoDB, for one, defaults to REPEATABLE READ, reads plain SELECTs from a snapshot but takes locks on index ranges for writes and locking reads, so the same name behaves differently (its manual).

keylines

  • the standard says what each level must prevent. a database may prevent more.
  • postgres: READ UNCOMMITTED = READ COMMITTED. dirty reads never happen.
  • REPEATABLE READ is snapshot isolation: one snapshot from the first statement, no phantoms, no protection from write skew.
  • REPEATABLE READ and SERIALIZABLE both answer conflicts with 40001. plan the retry.
  • pick by what your transaction decides: few known rows, READ COMMITTED; rules across rows, SERIALIZABLE.