Isolation Levels: READ COMMITTED, REPEATABLE READ, SERIALIZABLE
Compare the SQL standard isolation levels, PostgreSQL's implementation, and pick the right level for your workload.
Four Standard Levels
SQL standard defines four isolation levels:
- READ UNCOMMITTED
- READ COMMITTED
- REPEATABLE READ
- SERIALIZABLE
PostgreSQL implements three (READ UNCOMMITTED behaves like READ COMMITTED).
READ COMMITTED (PostgreSQL Default)
Each statement sees data committed before the statement started. You may see different snapshots within a single transaction.
-- Inside one transaction:
SELECT balance FROM accounts WHERE id = 1; -- 100
-- meanwhile another tx commits balance=200
SELECT balance FROM accounts WHERE id = 1; -- 200 (non-repeatable read)All lessons in this course
- ACID Properties and Anomalies
- Isolation Levels: READ COMMITTED, REPEATABLE READ, SERIALIZABLE
- Deadlocks: Detection and Avoidance
- Optimistic vs Pessimistic Locking