반응형
반응형

블로킹을 모니터링하는 예제 SP입니다.
master DB 생성해 두고 활용하면 편리합니다.
다음에 있는 SP는 웹에서 퍼온 SP입니다.

블로킹 점검 SP는 추후 작성이 되는 대로 추가로 예제 스크립트를 올리겠습니다.
 

create proc dbo.sp_block (@spid bigint=NULL)

as

-- This stored procedure is provided "AS IS" with no warranties, and confers no rights.

-- Use of included script samples are subject to the terms

-- specified at http://www.microsoft.com/info/cpyright.htm

select t1.resource_type

           , 'database'=db_name(resource_database_id)

           , 'blk object' =isnull(object_name(t1.resource_associated_entity_id) ,t1.resource_associated_entity_id)

           , t1.request_mode

           , t1.request_session_id   -- spid         

           , t2.blocking_session_id  -- spid         

from sys.dm_tran_locks as t1,

           sys.dm_os_waiting_tasks as t2

where t1.lock_owner_address = t2.resource_address

and t1.request_session_id = isnull(@spid,t1.request_session_id)

GO

 


CREATE PROC sp_block2000
AS
IF EXISTS (SELECT * FROM sysprocesses WHERE spid IN
                        (SELECT blocked FROM sysprocesses))
    SELECT spid, blocked, status, loginame, hostname,
        dbname = substring(db_name(dbid), 1, 10),
        cmd
    FROM sysprocesses
    WHERE blocked <> 0
        OR (spid IN (SELECT blocked FROM sysprocesses))
ELSE
    PRINT 'No one is blocked'

반응형

+ Recent posts

반응형