Saturday, December 2, 2017

Script to find Dirty/Clean Pages in SQL Server

I use below script to find out the dirty and clean pages in memory. Along with this,the script
will also give you the size for both Dirty and Clean pages: 


T-SQL Script:

SELECT *,
    [DirtyPageCount] * 8 / 1024 AS [DirtyPageMB],
    [CleanPageCount] * 8 / 1024 AS [CleanPageMB]
from
    (SELECT
        (CASE WHEN ([database_id] = 32767)
            THEN N'Resource Database'
            ELSE ([database_id]) END) AS [DatabaseName],
        SUM (CASE WHEN ([is_modified] = 1)
            THEN 1 ELSE 0 END) AS [DirtyPageCount],
        SUM (CASE WHEN ([is_modified] = 1)
            THEN 0 ELSE 1 END) AS [CleanPageCount]
    FROM sys.dm_os_buffer_descriptors
    GROUP BY [database_id]) AS [buffers]
ORDER BY [DatabaseName]
Go




Thank You!

Reference: Paul Randal Blog

No comments:

Post a Comment