CHECKPOINT vs DBCC DROPCLEANBUFFERS: Impact on Memory

CHECKPOINT vs DBCC DROPCLEANBUFFERS comes down to dirty pages and clean pages in the buffer pool. Today we will see how each command clears pages from the buffer memory pool. If you want help with your own server, see my Comprehensive Database Performance Health Check.

Diagram of the memory buffer with dirty and clean pages: after CHECKPOINT the dirty pages are written to disk and every page in memory is clean; after DBCC DROPCLEANBUFFERS the clean pages are removed from memory and the dirty pages stay

Dirty and Clean Buffers

To understand both commands, you first need two concepts: the clean buffer and the dirty buffer in memory. I suggest you read these two posts before you continue:

Now go to How Dirty or Clean Is SQL Server’s Memory? and run the query on that page. It gives a result similar to this one.

Query result listing each database with its pages in the buffer, dirty pages and clean pages; tempdb shows 33441 dirty pages and 4132 clean pages

CHECKPOINT

CHECKPOINT writes to disk all the data pages in the buffer cache that are modified but not yet written. In other words, it flushes all the modified dirty pages to disk. Let us see what it does to SQL Server memory.

CHECKPOINT
GO

Result after CHECKPOINT: AdventureWorks2014 shows 0 dirty pages and 4042 clean pages, with the Dirty Pages and Dirty Page (MB) cells circled in red

CHECKPOINT works on one database, so run it in the database you want to flush.

DBCC DROPCLEANBUFFERS

DBCC DROPCLEANBUFFERS removes from the cache all the buffers whose data is already on disk. In other words, it flushes the clean pages out of memory. These are the pages that were dirty before CHECKPOINT ran.

DBCC DROPCLEANBUFFERS
GO

Result after DBCC DROPCLEANBUFFERS: AdventureWorks2014 shows 0 clean pages and 6013 dirty pages, with the Clean Pages and Clean Page (MB) cells circled in red

This command works on the whole server. After you run it, the clean pages are gone from the buffer for all databases.

Run With Care

Note: do not run CHECKPOINT or DBCC DROPCLEANBUFFERS on a production server without a specific reason. CHECKPOINT is not as dangerous. DBCC DROPCLEANBUFFERS can lower your SQL Server performance for a while, until the cache is rebuilt.

I hope the examples make the impact of both commands on memory clear.

Quick reference card: CHECKPOINT vs DBCC DROPCLEANBUFFERS

CHECKPOINT is not a cache flush, it is a write to disk that leaves the pages in memory.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Cache, SQL Memory, SQL Scripts, SQL Server, SQL Server DBCC
Previous Post
Foreign Key Checks in Insert Plans: The Cost of Each Constraint
Next Post
Performance Condition Alerts: Warnings Before a Log File Fills

Related Posts

1 Comment. Leave new

  • Thank you with the explanation.

    I have one small question.
    Is DROPCLEANBUFFER and Lazy writer works on same algorithm (LRU) –> move pages to disk. What is the main difference between them then?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.