SELECT
ROW_NUMBER() OVER(ORDER BY [CPU_Time_Ms] DESC) AS [CPU Rank],[Database Name]
, [CPU_Time_Ms] AS [CPU Time (ms)]
, CAST([CPU_Time_Ms] * 1.0 / SUM([CPU_Time_Ms]) OVER() * 100.0 AS DECIMAL(5, 2)) AS [CPU Percent]
FROM
(
SELECT pa.DatabaseID, DB_Name(pa.DatabaseID) AS [Database Name], SUM(qs.total_worker_time/1000) AS [CPU_Time_Ms]
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY (SELECT CONVERT(int, value) AS [DatabaseID]
FROM sys.dm_exec_plan_attributes(qs.plan_handle)
WHERE attribute = N'dbid' ) AS pa
GROUP BY DatabaseID
) DB_CPU_Stats
WHERE [Database Name] IS NOT NULL
ORDER BY [CPU Rank]
SQL Server 查看 数据库 CPU 消耗情况
最新推荐文章于 2024-08-23 17:37:15 发布