Memory

如何在 DMV 中查詢 SQL Server 記憶體管理器性能計數器?

  • November 1, 2019

是否有任何系統目錄視圖或 DMV 可用於從 SQL Server:Memory Manager 的性能計數器下方查詢(例如在 SSMS 中)?

Free Memory (KB)
Target Server Memory
Total Server Memory
Maximum Workspace Memory (KB)
Database Cache Memory (KB)
Granted Workspace Memory (KB)
Lock Memory (KB)
Log Pool Memory (KB)
Optimizer Memory (KB)
Connection Memory (KB)
SQL Cache Memory (KB)
Reserved Server Memory (KB)
Stolen Server Memory (KB)

您可以在 DMV sys.dm_os_performance_counters中找到您尋求的資訊。

select object_name, 
      counter_name, 
      instance_name, 
      cntr_value, 
      cntr_type
 from sys.dm_os_performance_counters
where 1=1
  and [object_name] = 'SQLServer:Memory Manager'

更新了 Kevinwhat 的查詢,它將以 MB 為單位按降序輸出值,僅輸出我感興趣的那些計數器:

select
   replace(counter_name,' (KB)','')    [counter_name],
   cntr_value / 1024                   [MB]    
from sys.dm_os_performance_counters
where   [object_name] = 'SQLServer:Memory Manager'
   and counter_name not in ('External benefit of memory','Lock Blocks Allocated','Lock Owner Blocks Allocated','Lock Blocks','Lock Owner Blocks','Memory Grants Outstanding','Memory Grants Pending')
order by [MB] desc

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