Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Isolation Levels

Direct answer

Isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable, plus SQL Server Snapshot) decide which concurrency anomalies a transaction can see.

When to use this

Use it when results are inconsistent under concurrency or transactions fail with serialization errors.

First 30 seconds

1. Current level: SHOW transaction_isolation; / SELECT @@transaction_isolation; / DBCC USEROPTIONS.

2. Anomaly observed (non-repeatable read, phantom, lost update)?

3. Raise level or use SELECT … FOR UPDATE.

4. Handle retries.

5. Test.

Operational verification

transaction starts with an isolation level → snapshot/locks → visible data

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
Scope / prerequisiteUse it when results are inconsistent under concurrency or transactions fail with serialization errors.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Reproduce with two psql or mysql sessions. Confirm the application retries on serialization or deadlock errors.

Step 2 Common failures Narrow the fault

Read-then-update without FOR UPDATE can lose updates under read committed. Serializable without retry logic turns conflicts into user-facing errors. MySQL repeatable read uses gap locks that can block inserts.

Key points

Defaults: PostgreSQL and SQL Server Read Committed, MySQL InnoDB Repeatable Read. Higher isolation means more retries or blocking — applications must retry serialization failures.

Key checks
  • SHOW transaction_isolation; — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand

How it works

Under MVCC each transaction reads from a snapshot. In read committed, each statement gets a new snapshot; in repeatable read, the whole transaction uses one. Serializable adds checks for dangerous dependency patterns and aborts one transaction.

ReferenceImportant terms & boundaries3 sections · depth on demand

Levels and anomalies

LevelDirty readNon-repeatable readPhantom
Read UncommittedPossiblePossiblePossible
Read Committed (PostgreSQL, SQL Server default)NoPossiblePossible
Repeatable Read (MySQL InnoDB default)NoNoPossible (prevented by InnoDB next-key locks / PG snapshot)
SerializableNoNoNo

Higher levels mean more retries (serialization failures) or blocking; applications must retry such transactions.

In depth

The lost update — and three ways to prevent it

Two sessions read stock 10, each subtracts 1 and writes 9: one sale is lost. Under read committed this happens silently.

-- 1. Do it in one statement (best when possible)
UPDATE stock SET qty = qty - 1 WHERE sku = 'A1' AND qty > 0;

-- 2. Lock the row while deciding
BEGIN;
SELECT qty FROM stock WHERE sku = 'A1' FOR UPDATE;   -- second session waits here
UPDATE stock SET qty = 9 WHERE sku = 'A1';
COMMIT;

-- 3. Optimistic: version column, retry if 0 rows updated
UPDATE stock SET qty = 9, version = version + 1 WHERE sku = 'A1' AND version = 7;

Behaviour that differs between engines

PostgreSQLMySQL InnoDBSQL Server
Default levelRead committedRepeatable readRead committed (locking, unless RCSI is on)
Repeatable read conflictError could not serialize access → retryUpdates see the latest committed row (no error)Shared locks held to end
SerializableSSI: no blocking, may abort with serialization failureTurns plain SELECT into locking readsRange locks
Readers block writers?NoNo (consistent reads)Yes, unless READ_COMMITTED_SNAPSHOT

Retry is part of the design

At repeatable read and serializable in PostgreSQL, and on any deadlock everywhere, the database may abort a transaction that did nothing wrong. Retry the whole transaction on SQLSTATE 40001 (serialization failure) and 40P01 (deadlock); MySQL reports error 1213 for deadlocks.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Assuming default isolation prevents all anomalies.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
isolation levelstransaction isolation levelserializable retry
Confirmation

Confirm action

Continue?