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:
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
-- reads and changes
COMMIT;In MySQL it is common to configure the next transaction and then start it:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION;
-- reads and changes
COMMIT;What changes from case to case
The four standard names
| Level | Practical tip |
|---|---|
READ UNCOMMITTED | The nominally most permissive level. |
READ COMMITTED | Each read sees committed data, according to the engine's rules. |
REPEATABLE READ | Aims to give a transaction a more stable view across several reads. |
SERIALIZABLE | The 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.
- Identify which reads must be consistent with each other.
- Define which concurrent changes are acceptable.
- Check your engine's default.
- 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.