SQLServer: Administración: Revisar que consultas se están ejecutando


/*Querys que estan corriendo */
-- Versión 1*/
--set static io ON
--INSERT INTO [_monitor].[dbo].[transaccion] ([spid] ,[uid],[cpu],[login_time],[last_batch],[hostname],[program_name],[status],[cmd],[loginame],[text],[fechacrea])
SELECT r.spid, r.uid, r.physical_io, r.waittime, r.cpu, r.login_time, r.last_batch, r.hostname, r.program_name, r.status, r.cmd, r.loginame, t.text, getdate() as fechacrea
-- select t.*
--INTO [_monitor].[dbo].[transaccion]
FROM sys.sysprocesses r
Cross apply sys.dm_exec_sql_text([sql_handle]) t
where spid <> @@spid
and r.status in ('running','runnable','suspended', 'spinloop', 'background')
-- and r.hostname in ('DESARROLLO')
-- and r.spid = 162
-- order by r.status, r.cpu desc;
order by r.status, r.cpu desc;

-- Versión 2
SELECT R.session_id, S.login_name, S.program_name , S.login_time, 'B>>' as [bloqueo],  BS.session_id, '<<B' as [bloqueo], R.start_time, R.command, R.status, tr.text as [query_request], tc.text as [query_most_recent_sql_handle], R.cpu_time, R.reads, R.writes, R.logical_reads, R.blocking_session_id, R.database_id, DB_NAME(R.database_id) as database_name, C.connect_time, C.net_transport, C.protocol_type, C.client_net_address, S.host_name
FROM sys.dm_exec_requests R
INNER JOIN sys.dm_exec_sessions S on R.session_id = S.session_id
INNER JOIN sys.dm_exec_connections C on R.connection_id = C.connection_id
LEFT JOIN sys.dm_exec_sessions BS on R.blocking_session_id = BS.session_id
CROSS APPLY sys.dm_exec_sql_text (r.sql_handle) tr
CROSS APPLY sys.dm_exec_sql_text (c.most_recent_sql_handle) tc
where R.session_id <> @@spid
order by r.status, r.cpu_time desc;

-- Revisar CURSORES
SELECT c.session_id, c.cursor_id, c.name,  c.properties, c.creation_time, c.is_open, c.reads, c.writes, c.dormant_duration,  t.text, c.sql_handle
FROM sys.dm_exec_cursors (87) c
CROSS APPLY sys.dm_exec_sql_text (c.sql_handle) t
order by  c.creation_time desc

-- Matar session
-- kill 409;
-- kill 573;  

Comentarios

Entradas populares