Tuesday, 25 July 2017

MSSQL - How to clear all caches?

Script to clear all caches? (For example for performance debug)

  1. /*
  2. https://yabele.blogspot.com/2017/07/mssql-how-to-clear-all-caches.html
  3. */
  4. SET NOCOUNT ON;
  5. DECLARE @StartedAt DATETIME2 = GETDATE();
  6. CHECKPOINT;
  7. DBCC DROPCLEANBUFFERS;
  8. DBCC FREESYSTEMCACHE ('ALL');
  9. -- Query
  10. PRINT ' Elapsed time: ' + CAST(DATEDIFF(ms, @StartedAt, GETDATE()) AS VarChar(20)) + ' ms';

No comments:

Post a Comment

Note: only a member of this blog may post a comment.