---
title: "Transaction isolation levels: READ COMMITTED, REPEATABLE READ, SERIALIZABLE"
description: "Set the transaction isolation level in CoraDB and how READ COMMITTED, REPEATABLE READ and SERIALIZABLE behave, with examples."
url: "https://www.coradb.ai/manual/sql/transaction_isolation.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/transaction_isolation.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb isolation level, set transaction isolation level, get transaction isolation level, read committed, repeatable read, serializable, snapshot isolation, write skew, update re-evaluation"
---

# Transaction isolation levels: READ COMMITTED, REPEATABLE READ, SERIALIZABLE

The *isolation level* of a transaction determines how much it is affected by other transactions running at the same time. A higher level gives each transaction a more stable view of the data; a lower level allows more concurrency. CoraDB supports three levels:

| Level | Number | Snapshot | Non-repeatable / phantom reads | Concurrent update of the same row |
|---|---|---|---|---|
| [READ COMMITTED](https://www.coradb.ai/manual/sql/transaction_isolation.html#read-committed-isolation-level) (default) | 4 | New for each statement | Possible | Waits, then re-evaluates the row and continues |
| [REPEATABLE READ](https://www.coradb.ai/manual/sql/transaction_isolation.html#repeatable-read-isolation-level) | 5 | One for the whole transaction | no | Waits, then fails if the other transaction committed |
| [SERIALIZABLE](https://www.coradb.ai/manual/sql/transaction_isolation.html#serializable-isolation-level) | 6 | Same as **REPEATABLE READ** | no | Same as **REPEATABLE READ** |

At every level, dirty reads are impossible, readers never block writers, and the schema of a table that a running transaction has read cannot be changed until that transaction ends. Levels 1 to 3 of older versions are no longer supported. Background: [Concurrency and MVCC](https://www.coradb.ai/manual/sql/transaction_mvcc.html).


## SET TRANSACTION ISOLATION LEVEL

```sql
SET TRANSACTION ISOLATION LEVEL isolation_level [, LOCK TIMEOUT timeout_spec];

isolation_level:
    READ COMMITTED  | CURSOR STABILITY | 4
  | REPEATABLE READ | 5
  | SERIALIZABLE    | 6
```

```sql
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET TRANSACTION ISOLATION LEVEL 4;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, LOCK TIMEOUT 10;
```

Other values are rejected, for example `SET TRANSACTION ISOLATION LEVEL 3` fails with `Isolation level value in MVCC must be 'read committed', 'repeatable read' or 'serializable'.` For **LOCK TIMEOUT** see [Transaction lock timeout](https://www.coradb.ai/manual/sql/transaction_locking.html#transaction-lock-timeout).

The default for new sessions is set with the system parameter [isolation_level](https://www.coradb.ai/manual/admin/config_logging.html#isolation_level):

```text
# coradb.conf
isolation_level = 4
# or
isolation_level = "TRAN_READ_COMMITTED"
```

A new level applies from the next statement on, also inside a running transaction. Set it at the start of a transaction (after **COMMIT** or **ROLLBACK**) so that the whole transaction runs at one level.


## GET TRANSACTION ISOLATION LEVEL

```sql
GET TRANSACTION ISOLATION LEVEL [ { INTO | TO } :variable ];
```

Returns the isolation level of the current session, for example `READ COMMITTED`, or stores it in a host variable.

## Examples

The examples use two sessions with autocommit off (`;autocommit off` in corasql), each set to the level being shown. Steps run in order. They change rows of the e-commerce `product` table; the last step of each example restores the data.


## READ COMMITTED isolation level

**READ COMMITTED** (4) is the default. Each statement sees the data as committed when the statement started:

- Rows inserted by another transaction are invisible until it commits.
- A row being updated by another transaction can be read; you see its last committed version.
- A row being updated by another transaction cannot be updated at the same time. The second transaction waits, then [re-evaluates](https://www.coradb.ai/manual/sql/transaction_isolation.html#read-committed-update-re-evaluation) the committed row.
- Rows you are reading can be updated by others, and new rows can be inserted into the table.
- The schema of a table you have read cannot be changed by others until your transaction ends.
- Because every statement takes a new snapshot, the same query can return different results within one transaction (non-repeatable and phantom reads).

Only exclusive row locks are used for writing. No shared row locks are taken; the intent lock on each table read is kept until the end of the transaction, which keeps the schema stable.

**Example: non-repeatable read and stable schema**

| Step | Session 1 | Session 2 | Result |
|---|---|---|---|
| 1 | | `SELECT COUNT(*) FROM product WHERE units_in_stock < 5;` | 217 |
| 2 | `UPDATE product SET units_in_stock = 3, unit_price = 34.00 WHERE id = 1618;` then `COMMIT;` | | |
| 3 | | `SELECT COUNT(*) FROM product WHERE units_in_stock < 5;` | 218: the committed change is visible in the same transaction. |
| 4 | | `SELECT unit_price FROM product WHERE id = 1618;` | 34.00 (was 29.00) |
| 5 | `CREATE INDEX i_product_stock ON product (units_in_stock);` | | Waits: Session 2 has read `product` and its transaction is still open. |
| 6 | | `SELECT COUNT(*) FROM product WHERE units_in_stock < 5;` | 218: Session 2 keeps working on the same schema. |
| 7 | | `COMMIT;` | Session 1's **CREATE INDEX** continues. |
| 8 | `ROLLBACK;` then `UPDATE product SET units_in_stock = 22, unit_price = 29.00 WHERE id = 1618;` and `COMMIT;` | | Index removed, data restored. |


### Update re-evaluation

When a **READ COMMITTED** statement wants to change a row that another transaction has changed but not committed, it waits. When the other transaction commits, the statement does not fail (as it would under **REPEATABLE READ**). It reads the newly committed version and checks its search condition again:

- If the new version still matches, the statement changes the new version.
- If it no longer matches, the row is skipped, as if it had never matched.

Products 1607, 1620 and 1628 have 0, 4 and 4 units in stock. Session 2 discounts low-stock products by 5.00 while Session 1 restocks two of them:

| Step | Session 1 | Session 2 | Result |
|---|---|---|---|
| 1 | `UPDATE product SET units_in_stock = units_in_stock + 2 WHERE id = 1607;` `UPDATE product SET units_in_stock = units_in_stock + 10 WHERE id = 1620;` | | 1607 → 2, 1620 → 14 (not committed). Session 1 locks both rows. |
| 2 | | `UPDATE product SET unit_price = unit_price - 5 WHERE units_in_stock < 5 AND id IN (1607, 1620, 1628);` | Session 2's snapshot sees all three rows matching. It updates 1628 and waits for the lock on the next row. |
| 3 | `COMMIT;` | | |
| 4 | | | Session 2 continues. 1607 now has 2 units: still matches, discounted. 1620 now has 14 units: no longer matches, skipped. |
| 5 | | `SELECT id, unit_price, units_in_stock FROM product WHERE id IN (1607, 1620, 1628);` | 1607: 40.00, 2 · 1620: 49.00, 14 · 1628: 19.00, 4 |

To restore the data: `ROLLBACK;` in Session 2, then in Session 1 `UPDATE product SET units_in_stock = units_in_stock - 2 WHERE id = 1607; UPDATE product SET units_in_stock = units_in_stock - 10 WHERE id = 1620; COMMIT;`.


## REPEATABLE READ isolation level

**REPEATABLE READ** (5) gives each transaction one snapshot, taken by its first statement and kept until it ends:

- Rows inserted by another transaction are invisible, even after it commits.
- A row being updated by another transaction can be read; you see the version committed before your snapshot.
- A row that another transaction has changed and committed after your snapshot cannot be changed by you: the statement fails with `Serializable conflict due to concurrent updates`.
- Rows you are reading can be updated by others, and new rows can be inserted into the table; you just do not see the changes.
- The schema of a table you have read cannot be changed by others until your transaction ends.
- The same query returns the same result throughout the transaction: no non-repeatable or phantom reads.

**Example: a stable snapshot**

| Step | Session 1 | Session 2 | Result |
|---|---|---|---|
| 1 | | `SELECT COUNT(*) FROM product WHERE units_in_stock < 5;` | 217 |
| 2 | `UPDATE product SET units_in_stock = 3, unit_price = 34.00 WHERE id = 1618;` then `COMMIT;` | | Session 1 can change rows Session 2 has read. |
| 3 | | `SELECT COUNT(*) FROM product WHERE units_in_stock < 5;` | Still 217. |
| 4 | | `SELECT unit_price FROM product WHERE id = 1618;` | Still 29.00. |
| 5 | | `UPDATE product SET units_in_stock = units_in_stock + 1 WHERE id = 1618;` | Fails: `Serializable conflict due to concurrent updates`, because the row changed after Session 2's snapshot. |
| 6 | | `ROLLBACK;` then the same **SELECT**s | 218 and 34.00: a new transaction sees the committed data. |
| 7 | `UPDATE product SET units_in_stock = 22, unit_price = 29.00 WHERE id = 1618;` then `COMMIT;` | | Data restored. |

**Write skew.** Snapshot isolation does not make concurrent transactions serializable. Suppose the shop requires that products 1620 and 1628 (4 units each) together never run out of stock, and each session checks the rule before removing one product from sale:

| Step | Session 1 | Session 2 | Result |
|---|---|---|---|
| 1 | `SELECT SUM(units_in_stock) FROM product WHERE id IN (1620, 1628);` | `SELECT SUM(units_in_stock) FROM product WHERE id IN (1620, 1628);` | 8 in both sessions: the rule allows one product to go to 0. |
| 2 | `UPDATE product SET units_in_stock = 0 WHERE id = 1620;` then `COMMIT;` | `UPDATE product SET units_in_stock = 0 WHERE id = 1628;` then `COMMIT;` | Both succeed: they changed different rows. |
| 3 | `SELECT SUM(units_in_stock) FROM product WHERE id IN (1620, 1628);` | | 0: the rule is broken, although each transaction respected it. |

Run serially, the second transaction would have seen 4 and kept its product. To prevent write skew, make the transactions conflict on a common row, for example by updating a shared row that both read, or enforce the rule in a single statement. Restore the data with `UPDATE product SET units_in_stock = 4 WHERE id IN (1620, 1628); COMMIT;`.


## SERIALIZABLE isolation level

**SERIALIZABLE** (6) is accepted for compatibility but currently behaves exactly like **REPEATABLE READ**: it prevents non-repeatable and phantom reads through snapshot isolation, but not write skew. Applications that need full serializability must avoid write skew themselves, as described above.
