Sql-Server

如何查看 SQL Server 2008 記憶體中記憶體的內容?

  • March 20, 2022

有沒有辦法找出 SQL Server 2008 R2 中記憶體的內容?我找到了以下不錯的文章:http: //blog.sqlauthority.com/2010/06/17/sql-server-data-pages-in-buffer-pool-data-stored-in-memory-cache。但是,我想知道每個表和索引儲存了多少數據(例如百分比和 KB)。有沒有一些簡單的方法來獲取這些數據?

您可以使用以下查詢找到儲存在緩衝池(數據記憶體)中的內容:

這裡

select
      count(*)as cached_pages_count,
      obj.name as objectname,
      ind.name as indexname,
      obj.index_id as indexid
from sys.dm_os_buffer_descriptors as bd
   inner join
   (
       select       object_id as objectid,
                          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_id as objectid,
                          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
left outer join sys.indexes ind 
 on  obj.objectid = ind.object_id
and  obj.index_id = ind.index_id
where bd.database_id = db_id()
 and bd.page_type in ('data_page', 'index_page')
group by obj.name, ind.name, obj.index_id
order by cached_pages_count desc

優秀參考:儲存引擎內部:緩衝池中有什麼?由保羅蘭德爾。

您可以使用動態管理視圖列出目前記憶體的頁面並通過 database_id 過濾它們:

  select top 100 * from sys.dm_os_buffer_descriptors

然後您可以看到DBCC PAGE列出對象頁面的命令。很好的參考:http ://www.mssqltips.com/sqlservertip/1578/using-dbcc-page-to-examine-sql-server-table-and-index-data/

但是,將結果結合起來由您決定,這似乎不是一件容易的事:)。當您想出有效的方法來做到這一點時,請告訴我們。

引用自:https://dba.stackexchange.com/questions/43572