A dirty read happens when one transaction reads a value that another transaction has written but has not yet committed. If the writing transaction later rolls back, the reader has used a value that never became part of the database.
A simple example
Two transactions work on the same account balance:
- Transaction A changes the balance from 500 to 450. It does not commit yet.
- Transaction B reads the balance and sees 450.
- Transaction A rolls back, so the committed balance is still 500.
- Transaction B has already used 450 in its work, a value that was never committed.
Why it matters
A dirty read can lead to wrong decisions. A report, an approval or a calculation may rest on a figure that disappears when the writer rolls back.
It can also spread the problem. If the reader writes data based on the value it saw, the rollback of the first transaction can force the reader to roll back as well. This is called a cascading rollback, and it means other work has to be undone too.
How isolation levels control dirty reads
Isolation levels set how much one transaction can see of another transaction’s work before that work commits. The SQL standard defines four levels. READ UNCOMMITTED allows dirty reads. READ COMMITTED, REPEATABLE READ and SERIALIZABLE do not allow them.
Products do not all behave the same way:
- PostgreSQL accepts the READ UNCOMMITTED level but treats it as READ COMMITTED, so it does not return dirty reads.
- In SQL Server, the NOLOCK table hint and the READ UNCOMMITTED isolation level allow dirty reads.
Dirty reads and deferred or immediate modification
Dirty reads become possible when uncommitted changes are visible in the database. Under immediate database modification, a transaction’s writes are in the database while it runs, so another transaction can reach them unless isolation rules block it. For how those writes get into the database before commit, see What is immediate database modification and how does it work?
In the textbook deferred model, pending writes stay out of the database until commit, so other transactions cannot read them directly. The broader comparison is covered in deferred and immediate database modification.
How dirty reads differ from other read problems
Two related problems are often confused with dirty reads:
- A non-repeatable read happens when a transaction reads the same row twice and gets different values, because another transaction committed a change between the two reads.
- A phantom read happens when a repeated query returns new rows that another committed transaction has inserted.
Both involve committed data changing. A dirty read involves data that was never committed at all.
How to avoid dirty reads
- Use READ COMMITTED or a higher isolation level, unless the application can truly work with values that were never committed.
- Avoid NOLOCK hints and READ UNCOMMITTED for queries whose results must be correct.
- Keep transactions short, which reduces the time uncommitted changes stay visible.
- Accept dirty reads only for rough reporting where small errors do not matter, and make that choice on purpose.
Summary
- A dirty read returns a value that another transaction wrote but never committed.
- If that writer rolls back, the reader has used a value that never existed in the database.
- In the SQL standard, READ COMMITTED and stricter levels prevent dirty reads. Product behavior varies, so check the documentation for the system in use.