iT邦幫忙

第 12 屆 iThome 鐵人賽

2
自我挑戰組

回顧再出發~系列 第 21

[MSSQL維護] SQL 偵測 - 在忙什麼,為什麼這麼慢~~

  • 分享至 

  • xImage
  •  

不乖,就殺了你

KILL SPID 
KILL 83

Query在忙什麼?


if 1=1
SELECT      r.scheduler_id as 排程器識別碼,
            status         as 要求的狀態,
            r.session_id   as SPID,
            r.blocking_session_id as BlkBy,
            substring(
				ltrim(q.text),
				r.statement_start_offset/2+1,
				(CASE
                 WHEN r.statement_end_offset = -1
                 THEN LEN(CONVERT(nvarchar(MAX), q.text)) * 2
                 ELSE r.statement_end_offset
                 END - r.statement_start_offset)/2)
                 AS [query],
            r.cpu_time      as [CPU Time(ms)],
            r.start_time    as [開始時間],
            r.total_elapsed_time as [執行總時間],
            r.reads              as [讀取數],
            r.writes             as [寫入數],
            r.logical_reads      as [邏輯讀取數],
            -- q.text, /* 完整的 T-SQL 指令碼 */
            d.name               as [資料庫名稱]
FROM        sys.dm_exec_requests r 
			CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS q
			LEFT JOIN sys.databases d ON (r.database_id=d.database_id)
WHERE       r.session_id > 50 AND r.session_id <> @@SPID
ORDER BY    r.total_elapsed_time desc

排程在忙什麼?

if 1=1
begin

	SELECT
	'現在有什麼排程正在跑',run_requested_date,
	datediff(minute, activity.run_requested_date, getdate()) AS Elapsed
	,name x
	,*
	FROM msdb.dbo.sysjobs_view job
	INNER JOIN msdb.dbo.sysjobactivity activity ON (job.job_id = activity.job_id)
	WHERE 
	run_requested_date is not null
	AND start_execution_date is not null
	AND stop_execution_date is null
	AND activity.session_id=(select max(session_id) from msdb.dbo.syssessions)

end

IQ在忙什麼?

exec sp_context
sp_configure
sp_monitor 

上一篇
Cobol Picture Clause/cobol field type
下一篇
疫情學習用電腦麥克風
系列文
回顧再出發~22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言