sys.dm_exec_requests视图返回的是SQL Server中正在执行的每个请求的信息。也就是如果没有正在执行,是获取不到的。
SELECT r.session_id,
st.TEXT AS batch_text,
qp.query_plan AS 'XML Plan',
r.start_time,
r.status,
r.total_elapsed_time
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(r.plan_handle) AS qp
--WHERE DB_NAME(r.database_id) = '{db_name}'
ORDER BY cpu_time DESC;
如果发现某条sql执行很慢,可以使用 kill
终止
KILL spid; //中止会话session
查找当前阻止的所有请求
SELECT session_id,
status,
blocking_session_id,
wait_type,
wait_time,
wait_resource,
transaction_id
FROM sys.dm_exec_requests
WHERE status = N'suspended';
GO
标签:dm,排查,exec,sys,耗时,session,sql,SQL,id
From: https://www.cnblogs.com/kkbk/p/17729800.html