Skip to content
IT glossary
DatabasesUpdated December 3, 2026

Transaction isolation levels

Уровни изоляции транзакций

A transaction’s isolation level sets the rules for what it can see of other transactions’ changes and which problems the database prevents when they run at the same time.

Also known as: read committed, repeatable read, serializable

Why isolation matters

Suppose a report runs two queries: one counts pending orders, and the other lists them. If someone adds an order between those queries, the count and the list may disagree. Both queries can be correct on their own. The isolation level determines whether they can see different committed versions of the data even when they run inside the same transaction.

The anomalies behind the four levels

  • A dirty read sees a change that another transaction has not committed and might roll back.
  • A non-repeatable read occurs when a transaction reads the same row twice and gets a different value after another transaction commits an update.
  • A phantom read occurs when rerunning a query with the same filter returns a different set of rows. A newly inserted pending order is a phantom if it first appears on the second read.

Read Uncommitted is allowed to exhibit all three anomalies. Read Committed rules out dirty reads but permits the other two. Repeatable Read also rules out non-repeatable reads; the SQL standard still allows phantoms at this level, though PostgreSQL prevents them. Serializable goes beyond the list: the effect of committed transactions must be equivalent to running them one at a time in some order. The database can still run transactions concurrently and abort one if it cannot preserve that guarantee.

Walk through two PostgreSQL sessions

-- Session A
BEGIN ISOLATION LEVEL READ COMMITTED;
SELECT count(*) FROM orders WHERE status = 'pending'; -- 5

-- Session B inserts a pending order and commits.

-- Session A
SELECT count(*) FROM orders WHERE status = 'pending'; -- 6
COMMIT;

PostgreSQL defaults to Read Committed, where each plain SELECT takes a fresh snapshot: a view of the data at a particular point in time. Run this example at Repeatable Read and both counts are 5. The transaction keeps the snapshot established by its first query, so the later insert does not enter that view.

A consistent view is not always enough

A stable snapshot is useful when several report queries need to agree. But consider two doctors who both try to go off call. Each transaction sees the other doctor still on call and updates only its own doctor's row. At PostgreSQL's Repeatable Read level, both can commit, leaving nobody on call. This anomaly is called write skew: the transactions write different rows but make decisions based on the same outdated view. If both transactions check the rule at Serializable, the database prevents that outcome; the application should be ready to retry an aborted transaction in full so it checks the rule again.

What interviewers look for

When asked what a query will return, name the database and isolation level before tracing the reads and commits. If the question is about protecting a business rule, explain what could go wrong even with a stable snapshot. Don't assume two database engines make identical promises just because they use the same level name.