I have several db in my instance in SQL Server. I wonder which db consume more core from my computer.
How to find this information?
I have several db in my instance in SQL Server. I wonder which db consume more core from my computer.
How to find this information?
Yes, just as Sean states, however, here is a query which may help to point to which databases' queries are the most on the instance by querying aggregate performance statistics for cached query plans by db.
You'll want to pay attention to how old the plan cache is, since it's a volatile place, and prone to clearing out. It also has a lot of blind spots around queries and procedures with recompile hints, etc. If you have Query Store enabled, I'd suggest using that instead.
WITH
DB_CPU_Stats AS
(
SELECT
F_DB.database_id,
database_name = DB_NAME(F_DB.database_id),
cpu_time_seconds = SUM(qs.total_worker_time) / 60000000.,
min_creation_time = MIN(creation_time),
max_creation_time = MAX(creation_time),
total_execution_count = SUM(execution_count)
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY
(
SELECT
database_id = CONVERT(integer, p.value)
FROM sys.dm_exec_plan_attributes(qs.plan_handle) AS p
WHERE attribute = N'dbid'
) AS F_DB
GROUP BY
F_DB.database_id
)
SELECT
DB_CPU_Stats.database_name,
DB_CPU_Stats.cpu_time_seconds,
DB_CPU_Stats.min_creation_time,
DB_CPU_Stats.max_creation_time,
oldest_plan_days = DATEDIFF(DAY, DB_CPU_Stats.min_creation_time, SYSDATETIME()),
DB_CPU_Stats.total_execution_count,
[CPUPercent] =
CAST(DB_CPU_Stats.cpu_time_seconds * 1.0 /
SUM(DB_CPU_Stats.cpu_time_seconds) OVER () * 100.0 AS decimal(5, 2))
FROM DB_CPU_Stats
WHERE DB_CPU_Stats.database_id > 4
AND DB_CPU_Stats.database_id < 32767
ORDER BY
ROW_NUMBER() OVER
(
ORDER BY
DB_CPU_Stats.cpu_time_seconds DESC
)
OPTION (RECOMPILE);