如何查看在SQL Server 2008的内存中caching的内容?

有没有办法找出在SQL Server 2008 R2中caching的内容? 我在这里find了以下好的文章:

SQL SERVER – Data Pages in Buffer Pool – Data Stored in Memory Cache

但是,我想知道每个表和索引存储了多less数据(例如百分比和KB)。

是否有一些简单的机制来获取这些数据?

sys.dm_os_buffer_descriptors DMV有两列在这里是相关的:database_id和allocation_unit_id。 使用allocation_unit_id,你可以通过sys.partitions到sys.indexes,最后到sys.objects。 这似乎得到当前数据库的上下文中每个对象的计数。 必要时适应

SELECT s.name AS [schema_name] , o.name AS [object_name] , i.name AS [index_name] , COUNT( * ) FROM sys.dm_os_buffer_descriptors AS buff INNER JOIN sys.[allocation_units] AS au ON buff.allocation_unit_id = au.allocation_unit_id INNER JOIN sys.partitions part ON ( au.type IN ( 1, 3 ) AND au.[container_id] = part.[hobt_id] ) OR ( au.type = 2 AND au.[container_id] = part.[partition_id] ) INNER JOIN sys.data_spaces ds ON au.[data_space_id] = [ds].[data_space_id] INNER JOIN sys.[indexes] AS i ON part.[object_id] = i.[object_id] AND part.[index_id] = i.[index_id] INNER JOIN sys.[objects] AS o ON [i].[object_id] = [o].[object_id] INNER JOIN sys.schemas s ON [o].[schema_id] = [s].[schema_id] WHERE o.is_ms_shipped = 0 AND buff.database_id = DB_ID( ) GROUP BY s.name , o.name , i.name ORDER BY s.name , o.name , i.name 

这是一个声明,返回一些大小的信息…

 -- Breaks down buffers by object (table, index) in the buffer pool SELECT OBJECT_NAME(p.[object_id]) AS [ObjectName] , p.index_id , COUNT(*) / 128 AS [Buffer size(MB)] , COUNT(*) AS [Buffer_count] FROM sys.allocation_units AS a INNER JOIN sys.dm_os_buffer_descriptors AS b ON a.allocation_unit_id = b.allocation_unit_id INNER JOIN sys.partitions AS p ON a.container_id = p.hobt_id WHERE b.database_id = DB_ID() AND p.[object_id] > 100 -- exclude system objects GROUP BY p.[object_id] , p.index_id ORDER BY buffer_count DESC ;