我从另一个团队那里得到了有关在SQL Server中进行阻止的报告。看结果
Exec sp_who2
并从Glenn Berry的博客中查询
SELECT blocking.session_id AS blocking_session_id ,blocked.session_id AS blocked_session_id ,waitstats.wait_type AS blocking_resource ,waitstats.wait_duration_ms ,waitstats.resource_description ,blocked_cache.text AS blocked_text ,blocking_cache.text AS blocking_text FROM sys.dm_exec_connections AS blocking INNER JOIN sys.dm_exec_requests blocked ON blocking.session_id = blocked.blocking_session_id CROSS APPLY sys.dm_exec_sql_text(blocked.sql_handle) blocked_cache CROSS APPLY sys.dm_exec_sql_text(blocking.most_recent_sql_handle) blocking_cache INNER JOIN sys.dm_os_waiting_tasks waitstats ON waitstats.session_id = blocked.session_id
我希望不能发现任何被阻止的东西。多次运行,我开始发现有些东西出现了,但是下次运行查询时,blcoking消失了。
我创建了临时表 SELECT INTO
SELECT INTO
,blocking_cache.text AS blocking_text INTO #TempBlockingTable FROM sys.dm_exec_connections AS blocking
之后,将查询修改为INSERT INTO SELECT。现在,我可以运行查询多次,而不必担心结果会消失。
INSERT INTO SELECT
我一直运行查询大约10秒钟,直到最终得到一些结果。
SELECT * FROM #TempBlockingTable
看着resource_description柱,从sys.dm_os_waiting_tasks我发现,数据显示在下面的格式。
resource_description
sys.dm_os_waiting_tasks
<type-specific-description> id=lock<lock-hex-address> mode=<mode> associatedObjectId=<associated-obj-id>
sys.dm_os_waiting_tasks http://technet.microsoft.com/zh- cn/library/ms188743.aspx上的Microsoft文档没有针对的定义associatedObjectId
associatedObjectId
答案实际上来自Aaron Bertrand在Google网上论坛中找到的答案。要获得成功OBJECT_NAME,associatedObjectId您需要运行以下查询
OBJECT_NAME
SELECT OBJECT_NAME([object_id]) FROM sys.partitions WHERE partition_id = 456489945132196
此数字456489945132196表示associatedObjectIdfromresource_description列中from的值sys.dm_os_waiting_tasks
456489945132196