Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 12 / Topic 4 of 9

Isolation levels

How much of other transactions' progress may you see? The SQL dial, as Postgres implements it:

SHOW transaction_isolation;
 transaction_isolation 
-----------------------
 read committed
(1 row)
  • Read Committed (the default): each statement sees everything committed before it started. Between your statements, other commits become visible.
  • Repeatable Read: the whole transaction sees one frozen snapshot. Re-reads always agree; if your write would clobber someone's concurrent change, Postgres errors (could not serialize access) and you retry.
  • Serializable: Repeatable Read plus cross-transaction pattern checks — the result is as if transactions ran one at a time, or you get the retry error.
  • Read Uncommitted exists as a name but behaves as Read Committed — Postgres never shows dirty (uncommitted) data to anyone.

Watch the default's signature behaviour, then the snapshot fix — a real two-session transcript (Session A's statements on the left of time, B's interleaved):

-- Session A                                         -- Session B
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT price FROM products WHERE product_id = 3;
 price
--------
 799.00
(1 row)
                                                     UPDATE products SET price = 777.00
                                                     WHERE product_id = 3;  -- autocommits
SELECT price FROM products WHERE product_id = 3;
 price
--------
 799.00      ← still the snapshot's price
(1 row)
COMMIT;
SELECT price FROM products WHERE product_id = 3;
 price
--------
 777.00      ← now visible, transaction over
(1 row)

Under Read Committed, A's second SELECT would already have shown 777.00 — a non-repeatable read, legal at that level. Repeatable Read froze the world instead. Defaults are right for most OLTP work; reach for Repeatable Read when a multi-statement report must be internally consistent, and Serializable when invariants span rows (and write a retry loop — serialization errors are the feature, not a bug).

🧪 Quick quiz — answer from memory, then check.

  1. PostgreSQL's default isolation level?
  2. What must an application using Repeatable Read / Serializable be prepared to do?
Show the answers
  1. Read Committed (SHOW transaction_isolation says so; Read Uncommitted is accepted but behaves the same).
  2. Retry — concurrent conflicts surface as serialization errors on purpose.

Done here? The practice set for Part 12 — 6 exercises with solutions — is on the part page.

Search the guide