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
| Item | Value |
|---|---|
| Introduced | SQL Server 2014, Azure SQL |
| Database option | DELAYED_DURABILITY = DISABLED (default), ALLOWED, FORCED |
DISABLED | Every commit is fully durable. Per-commit settings are ignored |
ALLOWED | Chosen per commit with COMMIT WITH (DELAYED_DURABILITY = ON) |
FORCED | Every commit uses delayed durability |
| When the log is written to disk | The log buffer (about 60KB) fills, a fully durable commit in the same database, sp_flush_log runs, a clean shutdown |
| What can be lost | Commits 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 Server | PostgreSQL | InnoDB | Oracle | |
|---|---|---|---|---|
| Setting | DELAYED_DURABILITY, COMMIT WITH (...) | synchronous_commit = off | innodb_flush_log_at_trx_commit = 0 or 2 | COMMIT WRITE NOWAIT / BATCH, COMMIT_WAIT |
| Scope | Database, commit | Server, session, transaction | Server | System, session, commit |
| When the log is written | Log buffer fills or explicit flush | WAL writer interval (default 200ms) | About every 1 second | LGWR decides |
In the Articles
- 6.2 fsync: Confirming Writes to Persistent Media
- 6.3 Group Commit: Many Commits in One fsync
- 6.6 Differences Between DBMSs and What You Meet in Practice
NOTE The log buffer size and the features it cannot be combined with can vary with the version.