sys.dm_os_buffer_descriptors (Transact-SQL)

傳回有關目前正在 SQL Server 緩衝集區中所有資料頁的資訊。 這項檢視的輸出,可以用來決定依據資料庫、物件或是類型來散發緩衝集區中的資料頁。

當資料頁是從磁碟讀取時,此頁面會複製到 SQL Server 緩衝集區,而且會經由快取提供重複使用。 每個快取資料頁都具有一個緩衝區描述項。 緩衝區描述項會以唯一的方式識別由 SQL Server 執行個體目前快取的每個資料頁。 sys.dm_os_buffer_descriptors 會為所有的使用者和系統資料庫傳回快取頁面。 其中包括與 Resource 資料庫相關聯的頁面。

資料行名稱

資料類型

說明

database_id

int

與緩衝集區中之頁面相關聯的資料庫識別碼。 可為 Null。

file_id

int

儲存頁面之保存影像的檔案識別碼。 可為 Null。

page_id

int

檔案內的頁面識別碼。 可為 Null。

page_level

int

頁面的索引層級。 可為 Null。

allocation_unit_id

bigint

頁面的配置單位識別碼。 這個值可以用來聯結 sys.allocation_units。 可為 Null。

附註   針對在 SQL Server 2005 之前的 SQL Server 版本中建立的叢集索引,sys.dm_os_buffer_descriptors 可能會在 allocation_unit_id 中顯示不存在的值。

page_type

nvarchar(60)

頁面的類型,例如:資料頁或索引頁。 可為 Null。

row_count

int

頁面上的資料列數。 可為 Null。

free_space_in_bytes

int

頁面上的可用空間量 (以位元組為單位)。 可為 Null。

is_modified

bit

1 = 頁面從磁碟讀取之後,已經修改過了。 可為 Null。

numa_node

int

緩衝區的非統一記憶體存取節點。 可為 Null。

read_microsec

bigint

將頁面讀取至緩衝區所需的實際時間 (單位毫秒)。 這個數字會在重複使用緩衝區時重設。 可為 Null。

權限

需要伺服器的 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.partition_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;

請參閱

參考

sys.allocation_units (Transact-SQL)

動態管理檢視和函數 (Transact-SQL)

SQL Server 作業系統相關的動態管理檢視 (Transact-SQL)

概念

Resource 資料庫