Delayed Durability

In the default configuration, a SQL Server commit finishes after that transaction's log records reach disk (full durability). With Delayed Durability, the server puts the log records only into the in-memory log buffer, returns commit completion immediately, and writes the log later in batches. The time spent waiting for log writes (WRITELOG waits) shrinks, but if the server stops abruptly, commits that have not yet been written are lost.

Key Specs

ItemValue
IntroducedSQL Server 2014, Azure SQL
Database optionDELAYED_DURABILITY = DISABLED (default), ALLOWED, FORCED
DISABLEDEvery commit is fully durable. Per-commit settings are ignored
ALLOWEDChosen per commit with COMMIT WITH (DELAYED_DURABILITY = ON)
FORCEDEvery commit uses delayed durability
When the log is written to diskThe log buffer (about 60KB) fills, a fully durable commit in the same database, sp_flush_log runs, a clean shutdown
What can be lostCommits after the last log write. Data consistency is not broken

How It Works

Figure. Fully durable commit and delayed durable commit

sequenceDiagram
  participant App as Application
  participant Buf as Log buffer
  participant Disk as Log file
  App->>Buf: COMMIT (full durability)
  Buf->>Disk: Write log
  Disk-->>App: Commit complete after the write finishes
  App->>Buf: COMMIT (delayed durability)
  Buf-->>App: Commit complete immediately
  Buf->>Disk: Write in batch when the buffer fills or at sp_flush_log

Diagram notes: A fully durable commit tells the application it is complete only after the contents of the Log buffer are written to the Log file. A delayed durable commit reports completion as soon as the log records are in the Log buffer, and the log is written later, several commits at a time. If the server stops in between, commits that existed only in the buffer are undone during restart recovery.

When it helps. Workloads that commit a very large number of small transactions and have large WRITELOG waits because the log disk is slow. Because each commit is not waited for, throughput rises, and log writes become larger, so the number of I/Os drops.

Caution. The application receives commit completion, yet the data can disappear, so use it only for data you can recreate (intermediate load stages, log-type data). At important points (such as the end of a batch), flush the log with sp_flush_log. Rows from a delayed durable commit are visible to other sessions immediately.

Features it cannot be combined with. Distributed transactions and cross-database transactions are always fully durable. On failover (availability groups, log shipping), you can also lose as much log as had not been sent.

Configuration and Checks

SELECT name, delayed_durability_desc FROM sys.databases;
ALTER DATABASE tune SET DELAYED_DURABILITY = ALLOWED;

BEGIN TRANSACTION;
  INSERT INTO dbo.event_log (msg) VALUES (N'...');
COMMIT TRANSACTION WITH (DELAYED_DURABILITY = ON);

EXEC sys.sp_flush_log;      -- writes the delayed commits so far to disk

-- Are log write waits large?
SELECT wait_type, waiting_tasks_count, wait_time_ms
FROM sys.dm_os_wait_stats WHERE wait_type = 'WRITELOG';

Comparison with Other DBMSs

SQL ServerPostgreSQLInnoDBOracle
SettingDELAYED_DURABILITY, COMMIT WITH (...)synchronous_commit = offinnodb_flush_log_at_trx_commit = 0 or 2COMMIT WRITE NOWAIT / BATCH, COMMIT_WAIT
ScopeDatabase, commitServer, session, transactionServerSystem, session, commit
When the log is writtenLog buffer fills or explicit flushWAL writer interval (default 200ms)About every 1 secondLGWR decides

In the Articles

NOTE The log buffer size and the features it cannot be combined with can vary with the version.

Related pages