jueves, 23 de diciembre de 2021

SP_WHO2 Tunning BD Monitoreo

 Con sp_who2 se puede saber que procesos estan corriendo en el momento  










Con la siguiente consulta se puede ver cual es la sentencia que se esta ejecutando en base al SPID:

declare
    @spid int
,   @stmt_start int
,   @stmt_end int
,   @sql_handle binary(20)

set @spid = XXX -- LLENAR SPID

select  top 1
    @sql_handle = sql_handle
,   @stmt_start = case stmt_start when 0 then 0 else stmt_start / 2 end
,   @stmt_end = case stmt_end when -1 then -1 else stmt_end / 2 end
from    sys.sysprocesses
where   spid = @spid
order by ecid

SELECT
    SUBSTRING(  text,
            COALESCE(NULLIF(@stmt_start, 0), 1),
            CASE @stmt_end
                WHEN -1
                    THEN DATALENGTH(text)
                ELSE
                    (@stmt_end - @stmt_start)
                END
        )
FROM ::fn_get_sql(@sql_handle)

Obtendrá como resultado el SP o fracción de consulta que se esta ejecutando.

No hay comentarios:

Publicar un comentario

Comenta cualquier duda o recomendatorio.