开发者社区> 问答> 正文

技术运维问题-SQL Server使用- Mssql查看死锁


[font=微软雅黑, "]1) sql语句:
[font=微软雅黑, "] WITH    CTE_SID ( BSID, SID, sql_handle )[font=微软雅黑, "]        
[font=微软雅黑, "]  AS ( SELECT   blocking_session_id ,
[font=微软雅黑, "]                        session_id ,
[font=微软雅黑, "]                        sql_handle
[font=微软雅黑, "]               FROM     sys.dm_exec_requests
[font=微软雅黑, "]                WHERE    blocking_session_id <> 0
[font=微软雅黑, "]               UNION ALL
[font=微软雅黑, "]               SELECT   A.blocking_session_id ,
[font=微软雅黑, "]                        A.session_id ,
[font=微软雅黑, "]                        A.sql_handle
[font=微软雅黑, "]               FROM     sys.dm_exec_requests A
[font=微软雅黑, "]                        JOIN CTE_SID B ON A.SESSION_ID = B.BSID
[font=微软雅黑, "]             )
[font=微软雅黑, "]    SELECT  C.BSID ,
[font=微软雅黑, "]            C.SID ,
[font=微软雅黑, "]            S.login_name ,
[font=微软雅黑, "]            S.host_name ,
[font=微软雅黑, "]            S.status ,
[font=微软雅黑, "]            S.cpu_time ,
[font=微软雅黑, "]            S.memory_usage ,
[font=微软雅黑, "]            S.last_request_start_time ,
[font=微软雅黑, "]            S.last_request_end_time ,
[font=微软雅黑, "]            S.logical_reads ,
[font=微软雅黑, "]            S.row_count ,
[font=微软雅黑, "]            q.text
[font=微软雅黑, "]    FROM    CTE_SID C
[font=微软雅黑, "]            JOIN sys.dm_exec_sessions S ON C.sid = s.session_id
[font=微软雅黑, "]            CROSS APPLY sys.dm_exec_sql_text(C.sql_handle) Q
[font=微软雅黑, "]    ORDER BY sid
[font=微软雅黑, "] 2) 如果出现死锁或者堵塞现象,就会在执行结果中罗列出来
[font=微软雅黑, "]session id表示被阻塞的id
[font=微软雅黑, "]blocking_session_id 表示阻塞session id的id
[font=微软雅黑, "]
[font=微软雅黑, "]
[font=微软雅黑, "]
[font=微软雅黑, "]如果问题还存在,请联系 阿里云售后支持[font=微软雅黑, "]。

展开
收起
梨好橙 2018-09-29 22:01:22 1807 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载