SQLServer如何監(jiān)控阻塞會(huì)話
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
一、查詢阻塞和被阻塞的會(huì)話SELECT r.session_id AS [Blocked Session ID], r.blocking_session_id AS [Blocking Session ID], r.wait_type, r.wait_time, r.wait_resource, s1.program_name AS [Blocked Program Name], s1.login_name AS [Blocked Login], s2.program_name AS [Blocking Program Name], s2.login_name AS [Blocking Login], r.text AS [SQL Text] FROM sys.dm_exec_requests AS r LEFT JOIN sys.dm_exec_sessions AS s1 ON r.session_id = s1.session_id LEFT JOIN sys.dm_exec_sessions AS s2 ON r.blocking_session_id = s2.session_id CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS r WHERE r.blocking_session_id <> 0 二、找出阻塞的具體SQLSELECT r.session_id, r.blocking_session_id, t.text AS [SQL Text], r.wait_type, r.wait_time, r.wait_resource FROM sys.dm_exec_requests AS r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t WHERE r.blocking_session_id <> 0; 三、編寫C#程序,每隔10秒監(jiān)控SQL Server數(shù)據(jù)庫(kù)中的阻塞會(huì)話,定位出阻塞的根源會(huì)話并終止它們,同時(shí)記錄日志。
說(shuō)明
注意事項(xiàng)
轉(zhuǎn)自https://www.cnblogs.com/tianqing/p/18217020 作者:Eric Zhou 該文章在 2024/5/28 10:28:58 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |