Use DBCC FREEPROCCACHE to clear the procedure cache. Freeing the procedure cache would cause, for example, an ad-hoc SQL statement to be recompiled rather than reused from the cache. If observing through SQL Profiler, one can watch the Cache Remove events occur as DBCC FREEPROCCACHE goes to work. DBCC FREEPROCCACHE will invalidate all stored procedure plans that the optimizer has cached in memory and force SQL Server to compile new plans the next time those procedures are run. Let us learn how to clean cache.
Use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. DBCC DROPCLEANBUFFERS serves to empty the data cache. Any data loaded into the buffer cache due to the prior execution of a query is removed.
DBCC FREEPROCCACHE DBCC DROPCLEANBUFFERS
I hope you find this blog post about Clean Cache and Clean Buffer helpful.
If you have any questions, you can reach out to me via Twitter.
Here are a few of my recent videos which you may find interesting.
Arrow in Execution Plan – SQL in Sixty Seconds #136
Do you know what a single arrow means in an execution plan? While we popularly call it the arrow, there is a technical name for these little arrows.
SSMS Efficiency – Replace STAR – SQL in Sixty Seconds #130
You might have heard that SELECT * is bad for query performance. Let us learn in today’s video how we can replace STAR (*) by column name.
Cycle Clipboard Ring – SQL in Sixty Seconds #129
Copy (CTRL + C) and Paste (CTRL + V) are the friends of the DBAs and Developers. In SQL Server it is totally possible to use the Cycle Clipboard Ring.
Split Screen for SSMS Efficiency – SQL in Sixty Seconds #120
I often struggle to remember the changes done to the stored procedure and in this situation, the Split Screen of SSMS really comes in very handily.
Full-Screen Execution Plan – SQL in Sixty Seconds #117
There are two primary tools – 1) Execution Plan and 2) Statistics IO. In this blog post, we will see how we can get the full-screen execution plan.
Reference: Pinal Dave (https://blog.sqlauthority.com)
24 Comments. Leave new
Thanks for useful imformation.
You have not mention CHECKPOINT before run DBCC DROPCLEANBUFFERS.
As per MSDN, use CHECKPOINT to produce a cold buffer cache. DBCC DROPCLEANBUFFERS command remove all buffers from the buffer pool.
That means, Not DROPCLEANBUFFERS produce a cold buffer cache, it is CHECKPOINT. And we use DROPCLEANBUFFERS to remove pages from buffer pool. Cold buffer does not mean Buffer is clear.
Hi Pinal Dave
I have a Store Procedure running and this SP running with batch processing. with condition normal, the process around 10-15 minute. but If I try a several time, the process slow time to time, the process take a time until 30-45 minute.
I have do the clear cache with this command.
DBCC SHRINKDATABASE (ForestWork, TRUNCATEONLY);
use ForestWork
DBCC SHRINKFILE([ForestWork_log], 0, TRUNCATEONLY)
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
DBCC FREESESSIONCACHE
DBCC FREESYSTEMCACHE (‘ALL’) WITH MARK_IN_USE_FOR_REMOVAL;
After clear cache, the process still slow, but sometime the process back to normal about 10-15 minute. but it is only occasionally
Do you know, what we should do? is any cache or log still need to clear again?
Please let me know, if you have any idea.
Best Regards,
Heri
I really wish I can answer this one. It requires more research.