블로킹을 모니터링하는 예제 SP입니다.
master DB에 생성해 두고 활용하면 편리합니다.
다음에 있는 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 |
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'
'연구개발 > SQL2005' 카테고리의 다른 글
[SQL 2005 GUIDE] 명령프롬프트 유틸리티 (1) (0) | 2009.07.22 |
---|---|
[SQL 2005 GUIDE] SQLdiag (0) | 2009.07.22 |
[SQL 2005 GUIDE] 동적 관리 뷰 활용 - tempdb (0) | 2009.07.22 |
[SQL 2005 GUIDE] 동적 관리 뷰 활용 - 쿼리 실행 확인하기 (0) | 2009.07.22 |
[SQL 2005 GUIDE] 동적 관리 뷰 활용 - 실행중인 프로세스 확인하기 (0) | 2009.07.21 |