skip to content

You own a busy SQL Server OLTP database whose reports block writers; how do you decide whether to turn on READ_COMMITTED_SNAPSHOT for the whole database, and roll it out?

level: principalimportance: should knowfreq 45%

answer

  1. every reader changes at once
  2. code that counted on waiting
  3. fourteen bytes and a version store
  4. the longest transaction sets the size
  5. a switch that needs the database alone

basics

~20 s

READ_COMMITTED_SNAPSHOT changes every READ COMMITTED reader at once: reader-writer blocking disappears, but code that relied on blocking reads can act on stale data, and versions cost row space and store capacity. Audit that code and size the store first.

solid answer

~50 s

Microsoft recommends row-versioned `READ COMMITTED` for most applications unless one depends on the blocking of the lock-based level, so the decision is whether yours does. Find reads that assumed they would wait for an in-flight write: integrity checks in triggers or procedures that `SELECT` another table, read-then-update logic without `UPDLOCK`, and queue readers using `READPAST`, which SQL Server rejects under RCSI unless paired with `READCOMMITTEDLOCK`. Then size the cost: up to 14 bytes added to each row as it is modified, and a version store in `tempdb`, or in the database itself when accelerated database recovery is on, that grows with the longest-running transaction. Roll out by testing with RCSI on, watching version-store size and long transactions, and flipping in a quiet window, since the `ALTER DATABASE` needs the database to itself; `OFF` is the rollback. In SQL Server 2025, RCSI is also what lets optimized locking's lock after qualification work.

go deeper

for a junior

Recall that READ_COMMITTED_SNAPSHOT changes every READ COMMITTED reader in the database at once, so readers stop waiting for writers.

for a middle

Explain what each reader sees after the switch, what the 14-byte row overhead and the version store are, and why a long transaction makes the store grow.

for a senior

Show how you would find code relying on blocking, size and monitor the version store with the right DMVs, and handle the exclusive moment the switch needs.

for a principal

Own the call between RCSI everywhere, SNAPSHOT for reports only, or fixing the reports, and fold it into any 2025 optimized-locking adoption so the audit happens once.

## What the switch really changes `READ_COMMITTED_SNAPSHOT` (RCSI) is a **database-wide** option. Once it is `ON`, every session running at `READ COMMITTED`, SQL Server's default level, stops taking shared locks and reads the last committed version of each row as of the start of each statement. Nobody opts in and nobody can opt out except by naming another level or a table hint. That is its strength, because readers stop blocking writers without a code change, and its risk, because every reader's semantics change on the same day. The decision is therefore less "is row versioning good" than "does any code here depend on the old blocking". Microsoft's own guidance recommends row-versioned `READ COMMITTED` for applications unless they rely on the blocking behaviour of the lock-based level. ## Code that depends on blocking Look for patterns where a read used to **wait for an in-flight write and then see its result**: - **Integrity checks done by reading.** A trigger or procedure that checks another table, "does the parent row still exist", "is the stock still there", used to wait for a concurrent uncommitted change. Under RCSI it reads the last committed version and can pass a check that the in-flight transaction is about to invalidate. Add `READCOMMITTEDLOCK` to those reads or enforce the rule with a constraint. - **Read-then-write without a lock hint.** A `SELECT` followed by an `UPDATE` based on what it saw. It was never fully safe, but RCSI widens the window. Use an atomic `UPDATE ... WHERE`, or `UPDLOCK` on the read. - **Queue readers using `READPAST`.** SQL Server rejects `READPAST` at RCSI-based `READ COMMITTED` unless the query also specifies `READCOMMITTEDLOCK`, so these fail outright after the switch: find them before it. - **Tests that assert blocking.** Anything that expects a reader to wait will now pass straight through. ## What it costs | Cost | Detail | |---|---| | Row size | Up to **14 bytes** per row for versioning information, added the first time a row is modified or inserted; full pages can split | | Version store location | `tempdb`; or the database's **persistent version store** when accelerated database recovery is on | | Version store size | Grows with the **longest-running** transaction, because versions it might need can't be cleaned | | Failure when `tempdb` fills | The longest-running transactions that haven't generated versions are victimised (messages 3967, then 3966), and if shrinking fails, writes stop generating versions (3959) and readers needing them fail (3958) | | Failure when the persistent store fills | Reads continue but `UPDATE` and `DELETE`, which generate versions, fail | Every modification in the database is versioned once the option is on, whether or not a reader needs the version. A rough sizing rule from the documentation for the `tempdb` store is: twice the version data generated per minute, multiplied by the longest running time, in minutes, of a transaction. ## The alternatives a lead should weigh 1. **RCSI for the database**: one switch, no query changes, the semantics change described above. 2. **`SNAPSHOT` for the reports only**: `ALLOW_SNAPSHOT_ISOLATION ON` and `SET TRANSACTION ISOLATION LEVEL SNAPSHOT` in the reporting sessions. Other readers keep lock-based behaviour, but all writes are still versioned and only the reporting code changes. 3. **Fix the report**: an index or a narrower query shortens the blocking without touching isolation at all, and is worth doing in any case. 4. **Move the reports elsewhere**, such as a readable secondary, which is a high-availability design decision rather than an isolation one. ## A rollout plan 1. Inventory triggers, procedures and data-access code for the patterns above; fix or annotate each with a locking hint. 2. Size `tempdb`, or the database if accelerated database recovery is on, for the version store, and find the longest transactions the workload really runs. 3. Run the workload in a test environment with RCSI on and compare results, not just timings. 4. Switch in a quiet window. The `ALTER DATABASE ... SET READ_COMMITTED_SNAPSHOT ON` needs no other connections in the database; `WITH ROLLBACK IMMEDIATE` ends them. 5. Watch `sys.dm_tran_version_store_space_usage` for the `tempdb` store, or `sys.dm_tran_persistent_version_store_stats` for the persistent one, and `sys.dm_tran_active_snapshot_database_transactions` ordered by `elapsed_time_seconds` for transactions pinning versions. 6. Keep `OFF` as the rollback, which needs the same exclusive moment. ## The 2025 angle In SQL Server 2025, optimized locking's **lock after qualification** works only with RCSI on, so a team planning to adopt optimized locking is effectively deciding RCSI at the same time. Making that one decision, with one audit, is cheaper than making it twice.

  • Why can one forgotten session in SQL Server make the version store grow for hours after RCSI is turned on?
    Versions are kept as long as an active transaction might need them, and a transaction that generates or reads versions holds back cleanup for the whole store. A session left inside an open transaction, or a long report, therefore keeps every later version alive. Find it in `sys.dm_tran_active_snapshot_database_transactions` by `elapsed_time_seconds`, then end it or fix the code that leaves transactions open.
  • What does SQL Server do when the tempdb version store runs out of space under RCSI?
    It first shrinks the version store by marking the longest-running transactions that haven't generated versions as victims, logging message 3967; a victim that later reads a version gets 3966 and is rolled back. If space still runs out, writes continue without generating versions (message 3959) and transactions needing those missing versions fail with error 3958.

  • RCSI only affects sessions that ask for it with SET TRANSACTION ISOLATION LEVEL.
  • Turning on RCSI costs nothing until a report actually reads a row version.
  • Under RCSI a trigger's validation SELECT still waits for in-flight changes.
  • RCSI can be switched on while the application stays connected, with no wait.
  • The version store is always in tempdb, whatever the database's settings.

Assumes SQL Server 2025; the persistent version store needs accelerated database recovery (2019 and later), and lock after qualification, which depends on RCSI, arrived with optimized locking in 2025.