SQL Server Buffer Pool

The SQL Server buffer pool (buffer cache) is the memory area that holds 8KB pages read from the data files. SQL Server reads and writes data files without going through the operating system cache, so the buffer pool is the only data cache. For that reason, an instance uses most of its allowed memory as the buffer pool.

Key Specs

ItemValue
Size settingsmax server memory (the default is effectively unlimited), min server memory
Typical sizeMost of the memory left after the share for the operating system and other processes
Azure SQLSet automatically by service tier and vCore count
Eviction ruleLRU-2: decided by the last two access times
Dirty page writesLazy writer, checkpoints (new databases use indirect checkpoints since 2016, with a target recovery time of 60 seconds)
Prefetchingread-ahead: reads, in extent units, pages that a scan will read next
ExtensionBuffer pool extension (a second-level cache that keeps clean pages on SSD, since 2014)
Operating system cacheNot used

How It Works

LRU-2. SQL Server records the last two access times of each page and evicts pages starting with the one whose second most recent access is oldest. A page that was read only once has no second access record, so it leaves first, which makes it hard for a large scan to push out frequently used pages.

Lazy writer. When free buffers run short, the lazy writer clears buffers that have not been used for a while. If a page is dirty, it is first written to disk. When the operating system signals memory pressure, SQL Server shrinks the buffer pool and gives memory back.

Checkpoint. Indirect checkpoints write dirty pages steadily to keep to TARGET_RECOVERY_TIME (60 seconds by default). Unlike automatic checkpoints, they do not write everything at once, so I/O is spread evenly.

Operating system cache. SQL Server opens data files and log files without buffering (Windows FILE_FLAG_NO_BUFFERING, with write-through for writes). On Linux it uses direct I/O in the same way. As a result, there is no double caching, and setting max server memory too small shrinks the cache by the same amount.

Configuration and Checks

EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'max server memory (MB)', 24576; RECONFIGURE;

-- Buffer pool usage by database
SELECT DB_NAME(database_id) AS db, COUNT(*) * 8 / 1024 AS mb,
       SUM(CASE WHEN is_modified = 1 THEN 1 ELSE 0 END) * 8 / 1024 AS dirty_mb
FROM sys.dm_os_buffer_descriptors GROUP BY database_id ORDER BY mb DESC;

-- Average time a page stays in the buffer pool (seconds)
SELECT object_name, counter_name, cntr_value FROM sys.dm_os_performance_counters
WHERE counter_name = 'Page life expectancy';

In an execution plan, you can see the buffer use of a single statement through logical reads (read from the buffer pool), physical reads, and read-ahead reads from SET STATISTICS IO ON.

Comparison with Other DBMSs

SQL ServerPostgreSQLInnoDBOracle
Eviction ruleLRU-2Clock sweepMidpoint insertion LRUTouch count LRU
Operating system cacheNot usedUsed togetherUsually bypassedUsually bypassed

In the Articles

NOTE Defaults can vary by version and Azure service tier.

Related pages