返回有关 SQL Server 缓冲池中当前所有数据页的信息。可以使用该视图的输出,根据数据库、对象或类型来确定缓冲池内数据库页的分布。
当从磁盘读取数据页时,该数据页被复制到 SQL Server 缓冲池并被缓存以供重复使用。每个缓存的数据页都有一个缓冲描述符。缓冲描述符唯一地标识 SQL Server 实例中当前缓存的每个数据页。sys.dm_os_buffer_descriptors 返回所有用户数据库和系统数据库的缓存页。这包括与“资源”数据库相关的页。
| 列名 | 数据类型 | 说明 | 
|---|---|---|
| database_id | int | 与缓冲池中的页关联的数据库 ID。可为空值。 | 
| file_id | int | 存储页的持久化图像的文件 ID。可为空值 | 
| page_id | int | 文件中页的 ID。可为空值。 | 
| page_level | int | 页的索引级别。可为空值 | 
| allocation_unit_id | bigint | 页的分配单元的 ID。可使用此值联接 sys.allocation_units。可为空值。 注意 对于在 SQL Server 2005 之前的 SQL Server 版本中创建的聚集索引,sys.dm_os_buffer_descriptors 可能会在 allocation_unit_id 中显示不存在的值。 | 
| page_type | nvarchar(60) | 页的类型,例如:数据页或索引页。可为空值。有关详细信息,请参阅页和区。 | 
| row_count | int | 页中的行数。可为空值。 | 
| free_space_in_bytes | int | 页中的可用空间(字节)。可为空值。 | 
| is_modified | bit | 1 = 从磁盘读取页后已对其进行修改。可为空值。 | 
权限
需要对服务器具有 VIEW SERVER STATE 权限。
备注
sys.dm_os_buffer_descriptors 返回 Resource 数据库正在使用的页。sys.dm_os_buffer_descriptors 不会返回有关可用页、被盗用页或在读取时出错的页的信息。
| 从 | 到 | 依据 | 关系 | 
|---|---|---|---|
| sys.dm_os_buffer_descriptors | sys.databases | database_id | 多对一 | 
| sys.dm_os_buffer_descriptors | <userdb>.sys.allocation_units | allocation_unit_id | 多对一 | 
| sys.dm_os_buffer_descriptors | <userdb>.sys.database_files | file_id | 多对一 | 
示例
A. 返回每个数据库的缓存页计数
以下示例返回为每个数据库加载的页的计数。
SELECT count(*)AS cached_pages_count
    ,CASE database_id 
        WHEN 32767 THEN 'ResourceDb' 
        ELSE db_name(database_id) 
        END AS Database_name
FROM sys.dm_os_buffer_descriptors
GROUP BY db_name(database_id) ,database_id
ORDER BY cached_pages_count DESC
B. 返回当前数据库中每个对象的缓存页计数
以下示例返回为当前数据库中每个对象加载的页的计数。
SELECT count(*)AS cached_pages_count 
    ,name ,index_id 
FROM sys.dm_os_buffer_descriptors AS bd 
    INNER JOIN 
    (
        SELECT object_name(object_id) AS name 
            ,index_id ,allocation_unit_id
        FROM sys.allocation_units AS au
            INNER JOIN sys.partitions AS p 
                ON au.container_id = p.hobt_id 
                    AND (au.type = 1 OR au.type = 3)
        UNION ALL
        SELECT object_name(object_id) AS name   
            ,index_id, allocation_unit_id
        FROM sys.allocation_units AS au
            INNER JOIN sys.partitions AS p 
                ON au.container_id = p.hobt_id 
                    AND au.type = 2
    ) AS obj 
        ON bd.allocation_unit_id = obj.allocation_unit_id
WHERE database_id = db_id()
GROUP BY name, index_id 
ORDER BY cached_pages_count DESC
更改历史记录
| 发布日期 | 历史记录 | 
|---|---|
| 2006 年 7 月 17 日 | 
 | 
请参阅
参考
sys.allocation_units (Transact-SQL)
动态管理视图和函数
与 SQL Server 操作系统相关的动态管理视图