Skip to content
Back to Blog
Search
PostgreSQL / Concurrency• 27 Aug 2026• 5 min read

PostgreSQL accepts four isolation levels and runs three

Search for transaction isolation and you get the same table every time: four levels down the side, three anomalies across the top. That table describes the SQL standard. On PostgreSQL it is wrong in both directions: it warns about an anomaly that cannot happen and leaves out one that can.

I checked each level on PostgreSQL 16.15 with two overlapping connections. The numbers below are from those runs.

1. The fourth level is accepted and ignored

The server accepts READ UNCOMMITTED and reports it back:

BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SHOW transaction_isolation;
-- read uncommitted

I held an uncommitted update in one session and read from the other:

-- Session A                             -- Session B (READ UNCOMMITTED)
BEGIN;
UPDATE acct SET bal=999 WHERE id=1;
-- held, not committed
                                         SELECT bal FROM acct WHERE id=1;
                                         -- 100      <- not 999
ROLLBACK;

Session B read 100. I checked pg_stat_activity: the writer already had a transaction ID and its uncommitted 999 was not visible.

Under MVCC no other snapshot can see an uncommitted row version, so there is no code path that returns one. PostgreSQL accepts the keyword and runs Read Committed.

2. Read Committed: the default, and what it does not promise

Read Committed takes a fresh snapshot for each statement. Two reads in the same transaction can disagree:

-- Session A (READ COMMITTED)            -- Session B
BEGIN;
SELECT bal FROM acct WHERE id=1;
-- 100
                                         UPDATE acct SET bal=555 WHERE id=1;
                                         COMMIT;
SELECT bal FROM acct WHERE id=1;
-- 555        <- same transaction, different answer
COMMIT;

The same thing happens when a matching row is inserted between reads:

READ COMMITTED   count #1 = 2   count #2 = 3    <- phantom read
                 (a concurrent INSERT committed in between)

3. Repeatable Read blocks phantoms, which the standard does not require

I reran both examples at Repeatable Read:

non-repeatable read
  READ COMMITTED    read #1 = 100   read #2 = 555     changed
  REPEATABLE READ   read #1 = 100   read #2 = 100     stable

phantom read
  READ COMMITTED    count #1 = 2    count #2 = 3      phantom
  REPEATABLE READ   count #1 = 2    count #2 = 2      blocked
                    (outside the transaction: 3 rows, the INSERT did commit)

Both reads use one snapshot, taken at the first statement. A row committed later is missing because it is not in the snapshot; no lock hides it. The standard’s table allows phantoms at this level, so code that defends against them on PostgreSQL is defending against something that cannot occur.

4. “Repeatable Read means read locks” is off by three orders of magnitude

I timed a writer with one session holding a plain Repeatable Read SELECT, then with that session using FOR UPDATE:

CONTROL   holder ran SELECT ... FOR UPDATE   ->  writer waited 4003 ms
TEST      holder ran a plain SELECT at RR    ->  writer waited    1 ms

The writer took 1 ms with the plain read and 4,003 ms with the row lock. The four-second hold was the control.

An UPDATE writes a new row version beside the old one, so a writer has nothing to wait for and a reader with an older snapshot keeps seeing the older version. The level decides when your snapshot is taken, not how long you hold locks.

Two writers can still block each other, and an explicit FOR UPDATE still locks the row.

5. A stable snapshot does not make read-modify-write safe

Two transactions read a balance of 100. One adds 10 and the other adds 20:

READ COMMITTED    final bal = 120   no error
REPEATABLE READ   final bal = 110   ERROR 40001: could not serialize access
                                           due to concurrent update
SERIALIZABLE      final bal = 110   ERROR 40001: (same)

Read Committed committed both writes and returned 120. One update was lost.

Repeatable Read committed one and returned 40001 to the other. Retrying the failed transaction gave 130.

Retry the whole transaction so the calculation uses a fresh read:

for attempt in range(3):
    try:
        with conn.transaction():          # BEGIN ... COMMIT
            bal = read_balance(conn, 1)   # the read must happen inside the retry
            write_balance(conn, 1, bal + delta)
        break
    except psycopg.errors.SerializationFailure:
        if attempt == 2:
            raise
        time.sleep(0.05 * 2 ** attempt)   # back off, then take a fresh snapshot
For a balance increment, UPDATE acct SET bal = bal + 20 WHERE id = 1 avoids the separate read in the first place.

6. Write skew, the case for Serializable

Two people are on call. Each checks that the other is still on call, then updates their own row:

-- both sessions run exactly this, concurrently
BEGIN;
SELECT count(*) FROM duty WHERE on_call;      -- 2, so it is safe for me to leave
UPDATE duty SET on_call = false WHERE name = :me;
COMMIT;
REPEATABLE READ   0 people left on call    no error
SERIALIZABLE      1 person  left on call    ERROR 40001: could not serialize access
                                                  due to read/write dependencies
                                                  among transactions

Repeatable Read committed both and left nobody on call. The transactions wrote different rows, so there was no conflict to detect: each read a fact the other invalidated. That is write skew, and it is not in the standard’s table.

Serializable tracks read/write dependencies. In this test it aborted one transaction with 40001, preserving the rule.

7. Choosing, in order

  • If it can be one statement, make it one. An atomic UPDATE ... SET x = x + n needs no retry at any level.
  • Read Committed, the default, when two reads disagreeing is acceptable. Do not run read-modify-write on it: that is the 120 with no error.
  • Repeatable Read when a transaction needs one consistent view: reports, exports, multi-step reads. Bring the retry loop.
  • Serializable when correctness depends on an invariant across rows your transaction does not write: the on-call rule, double booking, any “at least one” or “at most N” rule.
  • Above Read Committed, retry the whole transaction on 40001.

On PostgreSQL, each level up trades a class of silent wrong answers for a retry you have to write, and the standard’s table does not show that trade.

PostgreSQL / ConcurrencyRSSBack to Blog