SQL Server下如何抓取阻塞语句和理解阻塞相关信息
在SQL Server下可以通过下面的SQL来抓取阻塞相关的语句。
SELECT t1.resource_type AS [锁类型], DB_NAME(resource_database_id) AS [数据库名], t1.resource_associated_entity_id AS [阻塞资源对象],t1.resource_description as [资源描述信息], t1.request_mode AS [请求的锁], t1.request_session_id AS [等待会话], t2.wait_duration_ms AS [等待时间], (SELECT [text] FROM sys.dm_exec_requests AS r WITH (NOLOCK) CROSS APPLY sys.dm_exec_sql_text(r.[sql_handle]) WHERE r.session_id = t1.request_session_id ) AS [等待会话执行的批SQL], (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 )/2) 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 [等待会话执行的SQL], t2.blocking_session_id AS [阻塞会话], (SELECT [text] FROM sys.sysprocesses AS p CROSS APPLY sys.dm_exec_sql_text(p.[sql_handle]) WHERE p.spid = t2.blocking_session_id ) AS [阻塞会话执行的批SQL] FROM sys.dm_tran_locks AS t1 WITH (NOLOCK) INNER JOIN sys.dm_os_waiting_tasks AS t2 WITH (NOLOCK) ON t1.lock_owner_address = t2.resource_address OPTION (RECOMPILE);
如果有阻塞时,结果如下:
上面表示
1:会话54被58阻塞
2:会话58在执行修改f1字段的全表操作
3:会话54在执行修改f2字段的全表操作
4:修改的表对应的数据库为tempdb
5:锁的类型为RID(行锁),等待的资源描述为5:40:0,相关的对象为2089670228251836416
6:请求的锁是U(更新锁)
7:操作等待了超过了300秒
附:锁只有相关信息可以参考(如果理解和解决阻塞)
SQL Server下如何抓取阻塞语句和理解阻塞相关信息
在SQL Server下可以通过下面的SQL来抓取阻塞相关的语句。 SELECT t1.resource_type AS [锁类型], DB_NAME(resource_database_id) A...
点击下载文档
本文2024-09-16 18:41:36发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-23794.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章