日期:2014-05-17 浏览次数:20603 次
select spid, a.status, hostname, cpu, physical_io, blocked,
plan_handle, qt.text ,
[Query] =
SUBSTRING (qt.text, b.statement_start_offset/2,
(CASE WHEN b.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE b.statement_end_offset END - b.statement_start_offset)/2),
cmd, b.wait_type, object_name(qt.objectid,qt.dbid) ObjectName, a.dbid,
a.request_id, convert(sysname, rtrim(loginame)) as loginname, spid as 'spid_sort',
program_name , b.start_time
from master.dbo.sysprocesses a, sys.dm_exec_requests b
CROSS APPLY sys.dm_exec_sql_text(b.sql_handle)as qt
where b.session_id = a.spid and a.status not in ('sleeping','background')
order by physical_io desc
--法2
select *, status,spid,hostname,program_name,cmd,cpu,physical_io,blocked,dbo.get_sql(sql_handle) sql,
dbid,request_id,convert(sysname, rtrim(loginame)) loginname,spid 'spid_sort',
substring(convert(varchar,last_batch,111),6,5 )+' ' +substring(convert(varchar,last_batch,113) ,13 ,8 ) 'st_batch_char'
from master.dbo.sysprocesses where status not in ('sleeping','background')
SELECT tl.request_session_id AS WaitingSessionID ,
wt.blocking_session_id AS BlockingSessionID ,
wt.resource_description ,
wt.wait_type ,
wt.wait_duration_ms ,
DB_NAME(tl.resource_database_id) AS DatabaseName ,
tl.resource_associated_entity_id AS WaitingAssociatedEntity ,
tl.resource_type AS WatingResourceType ,
tl.request_type AS WaitingRequestType ,
wrt.[text] AS WaitingTSql ,
btl.request_type AS BlockingRequestType ,
brt.[text] AS BlockingTsql
FROM sys.dm_tran_locks tl
INNER JOIN sys.dm_os_waiting_tasks wt ON tl.lock_owner_address = wt.resource_address
INNER JOIN sys.dm_exec_requests wr ON wr.session_id = tl.request_session_id
CROSS APPLY sys.dm_exec_sql_text(wr.sql_handle) AS wrt
LEFT JOIN sys.dm_exec_requests br ON br.session_id = wt.blocking_session_id