数据库系统异常排查之DMV(3)

来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:34 点击:

,(select text from sys.dm_exec_requests as r with(nolock)                 --- get sql for waiter   
cross apply sys.dm_exec_sql_text(r.sql_handle)    
where r.session_id = t1.request_session_id) as waiter_batch   
,(select substring(qt.text,r.statement_start_offset/2,    
(case when r.statement_end_offset = -1 then len(convert(nvarchar(max), qt.text)) * 2    
else r.statement_end_offset end - r.statement_start_offset)/2+1)    
from sys.dm_exec_requests as r with(nolock)    
cross apply sys.dm_exec_sql_text(r.sql_handle) as qt   
where r.session_id = t1.request_session_id) as waiter_stmt    --- statement executing now   
,t2.blocking_session_id as [blocker sid]                --- spid of blocker   
,(select text from sys.sysprocesses as p with(nolock)    --- get sql for blocker   
cross apply sys.dm_exec_sql_text(p.sql_handle)    
where p.spid = t2.blocking_session_id) as blocker_stmt,getdate() time  
from sys.dm_tran_locks as t1 with(nolock) , sys.dm_os_waiting_tasks as t2 with(nolock)     
where t1.lock_owner_address = t2.resource_address

2. 查看阻塞其他进程的进程(阻塞源头):
--阻塞其他session的session
select  t2.blocking_session_id,COUNT(0) counts
from sys.dm_tran_locks as t1 with(nolock) , sys.dm_os_waiting_tasks as t2 with(nolock)   
where t1.lock_owner_address = t2.resource_address
group by blocking_session_id
order by 2

3. 被阻塞时间最长的进程:
--被阻塞时间最长的session
select top 10  t1.resource_type as [lock type] ,db_name(resource_database_id) as [database]   
,t1.resource_associated_entity_id as [blk object]   
,t1.request_mode as [lock req]                          -- lock requested   
,t1.request_session_id as [waiter sid]                      -- spid of waiter   
,t2.wait_duration_ms as [wait time]         
,(select text from sys.dm_exec_requests as r with(nolock)                 --- get sql for waiter   
cross apply sys.dm_exec_sql_text(r.sql_handle)    
where r.session_id = t1.request_session_id) as waiter_batch   
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • sql常见面试题
  • SQL SERVER 2005性能之跟踪
  • SQL编程(一)
  • LINUX上RMAN自动备份脚本
  • sql server面试题
  • 如何将多个SQL查询统计结果一次显示出来
  • 浅谈SQL Server中的事务日志(三)----在简单恢复模式下日志的角色
  • SQL小技巧系列 --- 行转列合并
  • sql server 列转行
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1