Concept · Modifying data

Transaction isolation levels

The isolation level decides what a transaction can see while others are working, and how conflicts between them are resolved.

Before continuing: This entry is part of the transactions guide. If you are new to the topic, start with BEGIN / START TRANSACTION.

Example

In PostgreSQL you can set the isolation level when you start a transaction:

PostgreSQL
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
-- reads and changes
COMMIT;

In MySQL it is common to configure the next transaction and then start it:

MySQL 8.4
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION;
-- reads and changes
COMMIT;

What changes from case to case

The four standard names

LevelPractical tip
READ UNCOMMITTEDThe nominally most permissive level.
READ COMMITTEDEach read sees committed data, according to the engine's rules.
REPEATABLE READAims to give a transaction a more stable view across several reads.
SERIALIZABLEThe strictest level; the result must be compatible with some serial execution of the transactions.

The names are standard, but the implementation is not identical. PostgreSQL, for example, accepts all four names even though READ UNCOMMITTED behaves like READ COMMITTED. MySQL's InnoDB offers all four and uses REPEATABLE READ as the default.

How to reason about the choice

Do not pick a level just because it seems “safer”. Stricter isolation can change concurrency, locking, retries or serialisation errors. The choice belongs to the application design and should be tested against its real read and write patterns.

  1. Identify which reads must be consistent with each other.
  2. Define which concurrent changes are acceptable.
  3. Check your engine's default.
  4. Design the application to handle conflicts and retries where needed.

SQLite has a different model

SQLite does not expose the four standard levels in the same way as PostgreSQL or InnoDB. Its documentation describes isolation between connections and explains that, except in specific shared-cache cases with PRAGMA read_uncommitted, separate connections do not see other connections' uncommitted changes. That is why you should not carry a SET TRANSACTION ISOLATION LEVEL recipe straight over to SQLite.