How to clear execution plan and buffer cache in SQL Server

The content explains how to clear SQL Server’s execution plan cache and buffer cache. DBCC FREEPROCCACHE removes cached plans globally, while ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE targets one database. To clear clean data pages, run CHECKPOINT first to write dirty pages to disk, then execute DBCC DROPCLEANBUFFERS.

Clear execution plan cache

This removes cached execution plans. SQL Server will compile new plans as queries run again.

DBCC FREEPROCCACHE;
GO

For one database only:

USE YourDatabaseName;
GO
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
GO

Clear clean data pages from buffer cache

CHECKPOINT writes dirty pages to disk, then DBCC DROPCLEANBUFFERS removes clean pages from the buffer pool.

CHECKPOINT;
GO
DBCC DROPCLEANBUFFERS;
GO

Leave a Reply