Insights

Fewer Deadlocks and Less Blocking: Read Committed Snapshot in SQL Server

If people using your application see screens hang while someone runs a large report, or meet the occasional “chosen as the deadlock victim” error, the cause is often the way SQL Server reads data by default. Read committed snapshot isolation lets each query read the last committed version of a row instead of waiting for locks, so reading and saving stop getting in each other’s way. It is a single database setting, and it is already the default in Azure SQL Database.

Why the Default Waits

Under SQL Server’s default, read committed with locking, a query takes shared locks as it reads. Those locks stop it from reading rows another transaction has changed until that transaction finishes. So a long save holds up every report that touches its rows, and the people waiting see a frozen screen.

A deadlock is the worst case: two sessions each hold something the other needs. SQL Server ends it by cancelling one of them, and that person’s work fails with an error. In business applications, many deadlocks are a report and a save tripping over each other.

What Read Committed Snapshot Changes

  • Each statement sees a consistent snapshot of the data as it was committed when the statement started.
  • Reads take no shared locks on rows, so a report never waits for a save, and a save never waits for a report.
  • Saves still take turns. Two people changing the same row still wait for each other, as they should.
  • Most applications need no code changes, because the setting changes how the database reads, not the SQL the application sends.

How to Turn It On

One statement switches it on: ALTER DATABASE [YourDatabase] SET READ_COMMITTED_SNAPSHOT ON; No other connection may be open in the database while it runs, so choose a quiet moment. Adding WITH ROLLBACK IMMEDIATE closes the other connections for you, rolling back any work they have not saved. The is_read_committed_snapshot_on column of sys.databases shows whether it is on.

What to Check First

  • Room for row versions. SQL Server keeps the earlier versions of changed rows in tempdb, or in the database itself when accelerated database recovery is on. Give that space room, and watch for very long transactions, which keep old versions from being cleaned up.
  • Read-then-save logic. Code that reads a value and then saves a change based on it, such as the next invoice number or a stock count, was never fully safe, but blocking often hid the problem. With read committed snapshot the read no longer waits for someone else’s save, so make it safe: read with the UPDLOCK hint, or do the read and the change in one UPDATE statement.
  • A realistic test. Turn it on in a copy of the database and run the application under a normal day’s load before you change the live one.

SQL Server 2025 Goes Further

SQL Server 2025 adds optimized locking, which reduces lock memory and blocking further and avoids lock escalation. One of its parts, lock after qualification, works only when read committed snapshot is on. It needs accelerated database recovery first, and it is off by default, enabled database by database. So turning on read committed snapshot now is also the first step toward it.

Every Light Speed database on SQL Server runs with read committed snapshot, so a report reads the last saved values instead of waiting for a long save to finish. See how Light Speed keeps databases fast.

Sources

Get started

Let’s Talk About Your Next Application

Tell us what you need to build, replace or rescue. We will listen, and give you an honest view of how we would approach it.