Isolation anomaly simulator
When two transactions touch the same data at the same time, the database has to decide what each one is allowed to see. The isolation level is that decision. A weaker level lets more transactions run side by side but lets more strange results through. A stronger level avoids them and sometimes cancels a transaction to do it.
T1 read the same row twice and got 100, then 150.
T1 reads the same balance twice. T2 changes it and commits between the two reads.
- T1Statement 1
BEGIN ISOLATION LEVEL READ COMMITTEDBEGIN
No snapshot yet: read committed takes one per statement.
- T2Statement 2
BEGIN ISOLATION LEVEL READ COMMITTEDBEGIN
No snapshot yet: read committed takes one per statement.
- T1Statement 3
SELECT balance FROM accounts WHERE id = 1balance = 100
Read committed takes a new snapshot for every statement: it sees everything committed so far.
- T2Statement 4
UPDATE accounts SET balance = 150 WHERE id = 1UPDATE 1
The change is visible only to T2 until it commits.
- T2Statement 5
COMMITCOMMIT
T2’s changes become visible to snapshots taken from now on.
- T1Statement 6
SELECT balance FROM accounts WHERE id = 1balance = 150
Read committed takes a new snapshot for every statement: it sees everything committed so far.
- T1Statement 7
COMMITCOMMIT
T1’s changes become visible to snapshots taken from now on.
Committed data
| id | balance |
|---|---|
| 1 | 150 |
Transactions
- T1 committed
- T2 committed
T1 read the same row twice and got 100, then 150.
Scenario and level
What each level allows in PostgreSQL
Every cell is a run of the simulator. “Happens” means the anomaly occurs, “Aborted” means PostgreSQL cancels a transaction to prevent it, and “Prevented” means both transactions finish with a correct result. Select a cell to replay it.
| Anomaly | Read uncommitted | Read committed | Repeatable read | Serializable |
|---|---|---|---|---|
| Dirty read | ||||
| Non-repeatable read | ||||
| Phantom read | ||||
| Lost update | ||||
| Write skew |
What it shows
When two transactions touch the same data at once, the isolation level decides what each may see. A weaker level lets more strange results through. A stronger one avoids them, and sometimes cancels a transaction to do so.
The tool runs two scripted transactions, T1 and T2, one statement at a time, under PostgreSQL’s rules. PostgreSQL runs read uncommitted as read committed.
How to read it
- The page opens on a finished run. Press Start over, then Next statement or Play to step through.
- T1 statements sit in the left lane and T2 in the right. Each card shows the SQL, what it returned and why.
- “Committed data” is the table as other sessions see it. “Transactions” shows each one’s state and uncommitted changes.
- The outcome appears after the last statement: the anomaly happened, PostgreSQL aborted a transaction, or the result was correct.
- In the table, each cell reads Happens, Aborted or Prevented. Select a cell to replay it.
- For lost update, a switch moves the arithmetic into SQL, which is the usual fix.
Questions
Why does read uncommitted behave like read committed here?
Because that is what PostgreSQL does. The manual says its read uncommitted mode behaves like read committed, so a transaction never sees another transaction’s uncommitted changes. Some other databases, such as SQL Server, genuinely allow dirty reads at this level.
What is the difference between a non-repeatable read and a phantom read?
A non-repeatable read is when a row you already read changes or disappears. A phantom is when a query that matches a set of rows, such as a count or a range, returns different rows the second time because another transaction inserted or removed one. In PostgreSQL both go away at repeatable read, because every statement reads the same snapshot.
What is write skew and why does repeatable read allow it?
Two transactions each read the same data, decide something based on it, and then write to different rows. Neither overwrites the other, so snapshot isolation sees no conflict, yet the combined result breaks a rule that each transaction checked on its own. In the on-call example both doctors see two on call, both go off, and nobody is left. Only serializable catches this.
Why did PostgreSQL abort one of my transactions?
Repeatable read aborts an update when the row was changed by a transaction that committed after your snapshot. Serializable aborts when it finds read and write dependencies that could not be ordered one after the other. In both cases the application is expected to retry the transaction from the start.
Does this behave the same in MySQL or Oracle?
No. Isolation levels are defined by the anomalies they forbid, and each database picks its own mechanism. MySQL’s InnoDB repeatable read uses a snapshot too but locks differently on writes. Oracle has no repeatable read and calls its snapshot level serializable. Check your database’s manual before relying on a result from this page.
Learn it properly
Sources
Explore further
- HermitageMartin Kleppmann’s tests of which anomalies each database’s isolation levels actually allow.
Last updated
More tools
All tools- estimatorBack-of-envelope estimatorTurn daily users into requests per second, storage and bandwidth, with the working shown.Open tool
- simulatorConsistent hashing simulatorA hash ring with virtual nodes: key spread per node, and how many keys move when the cluster changes.Open tool
- estimatorQueue latency estimatorWhy latency explodes as servers get busy: utilisation, waiting time and Little’s law.Open tool