Clear SQL Server Data & Plan Cache

Hi Friends,

Performance tuning/ Query tuning in SQL Server is a combo of art and science. During the query tuning, we sometimes need to clear the cache for actual benchmarking purposes. Here is the code to do that:

To clear data from cache globally:

DBCC DROPCLEANBUFFERS;
To clear execution plans from cache globally:

   

DBCC FREEPROCCACHE;
To clear execution plans of a particular database:

DBCC FLUSHPROCINDB(<db_id>);

The above command is undocumented.

Note: Be careful of using the above commands in your productuon enviornments. It may impact performence negatively to a good extent. We use it more to analyze performance in test enviornments.

 

 

   

About Amit Bansal

Amit Bansal is always brainstorming around SQL Server. Despite working with SQL since 1997, he is amazed that he keeps learning new things every single day. SQL Server is AB's first love, and his wife does not mind that. He tries to share as much and spreads the SQL goodness. Internals and Performance Tuning excites him, and also gives him sleepless nights at times, simply because he is not a genius, but quite a hard worker and does not give up. It has been a long and exciting journey since 1997, you can read here: http://sqlmaestros.com/amit-bansal/ He is on Twitter: https://www.twitter.com/A_Bansal

View all posts by Amit Bansal →

Leave a Reply

Your email address will not be published.