Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out what is hammering my SQL Server?

My SQL Server CPU has been at around 90% for the most part of today.

I am not in a position to be able to restart it due to it being in constant use.

Is it possible to find out what within SQL is causing such a CPU overload?

I have run SQL Profiler but so much is going on it's difficult to tell if anything in particular is causing it.

I have run sp_who2 but am not sure what everything means exactly and if it is possible to identify possible problems in here.

To pre-empt any "it's probably just being used a lot" responses, this has only kicked in today from perfectly normal activitly levels.

I'm after any way of finding what is causing CPU grief within SQL.

like image 597
joshcomley Avatar asked Jun 03 '09 14:06

joshcomley


People also ask

How do you check what is running in SQL Server?

You can view this by Right Clicking on Instance Name in SQL Server Management Studio and selecting “Activity Monitor”. Activity monitor tells you what the current and recent activities are in your SQL Server Instance.

Why is SQL Server memory usage so high?

SQL Server will consume all of the available memory. By default, that number corresponds to the total amount of numeric memory available on your computer. As a result, your perceptions are correct. To put it another way, if you give SQL Server 24 GB of memory, it will make every effort to make the most of that memory.


1 Answers

This query uses DMV's to identify the most costly queries by CPU

SELECT TOP 20     qs.sql_handle,     qs.execution_count,     qs.total_worker_time AS Total_CPU,     total_CPU_inSeconds = --Converted from microseconds         qs.total_worker_time/1000000,     average_CPU_inSeconds = --Converted from microseconds         (qs.total_worker_time/1000000) / qs.execution_count,     qs.total_elapsed_time,     total_elapsed_time_inSeconds = --Converted from microseconds         qs.total_elapsed_time/1000000,     st.text,     qp.query_plan FROM     sys.dm_exec_query_stats AS qs CROSS APPLY      sys.dm_exec_sql_text(qs.sql_handle) AS st CROSS APPLY     sys.dm_exec_query_plan (qs.plan_handle) AS qp ORDER BY      qs.total_worker_time DESC 

For a complete explanation see: How to identify the most costly SQL Server queries by CPU

like image 180
John Sansom Avatar answered Nov 16 '22 00:11

John Sansom