How it works
Without isolation, two specific things go wrong. A dirty read is seeing another transaction’s uncommitted write. A report that runs while Ana’s transfer is half done sees her debit but not Ben’s credit, so $50 looks missing. If the transfer then aborts, the report has acted on a value that never officially existed.
A dirty write is overwriting another transaction’s uncommitted write. Suppose T1 lowers Ana’s balance from 200 to 150 without committing, and a support tool then sets it to 500. If T1 aborts and restores 200, the support tool’s write is gone even though it committed. Rollback only works when one transaction at a time owns a row’s uncommitted value.
Read committed isolation forbids both. A transaction takes a row lock when it first updates a row and holds it until it commits or aborts, so a second writer waits. For reads, multi-version engines such as Postgres and Oracle keep the last committed value alongside the new one and return that, so readers do not wait. Follow one row. T1 debits Ana, writing 150 uncommitted. T2 reads Ana and immediately gets 200. T3 tries to subtract 20 and blocks on T1’s lock. T1 commits. T2’s next read returns 150, and T3 resumes against the new value, leaving 130.
This level is cheap, and Postgres and Oracle both default to it, but it protects each read rather than a sequence of them. Two reads in one transaction can return different committed values, and writers can still overwrite updates computed from an earlier read.
Checkout marks an order paid and inserts a shipment row in one transaction. A warehouse dashboard, polling during checkout, sometimes shows paid orders with no shipment. The database runs at read committed. A teammate blames dirty reads. Is that right, and what would you check?
Probably not, since read committed forbids dirty reads. Check the dashboard’s statement order. If it reads shipments first and orders second, checkout can commit between the two: it sees no shipment, then a paid order. Both values were committed, just at different moments. Read both tables in one statement, which gets a single view at this level in Postgres, or run the dashboard at a snapshot level.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Dirty reads see unfinished work; dirty writes overwrite it.
- Row locks hold back writers, while old committed versions keep readers moving.
- Read committed protects each read, not a sequence of reads.