Lesson 2 · Unit 03
Isolation levels
What one transaction may see of another
What you practise
- Dirty reads, non-repeatable reads, phantoms
- Read committed, repeatable read, serializable
- Snapshots
- What Postgres does by default
Try a question from this lesson
Pick one
Ana's balance is 100. T1 changes it, then changes its mind. What is the only safe value for T2's SELECT to return?
T1 T2
BEGIN
UPDATE: balance = 0
SELECT balance
ROLLBACKCorrect answer
100
Why
The 0 was never committed, and after the rollback it never existed. Had T2 seen it, T2 would have acted on fiction. That is a dirty read, and Postgres never allows one.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Isolation is a dial
Transactions run at the same time. Isolation decides how much they see of each other.
The SQL standard names four levels, loosest to strictest: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.
Stricter levels rule out more surprises, and cost more waiting or more retries. You pick per transaction.
10 more exercises in the app
- 4× multiple choice
- 2× type the answer
- 1× match the pairs
- 1× true or false
- 1× fill the blanks
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.