HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How can I convert a key in a SQL Server deadlock report to the value?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cantheconvertsqldeadlockvaluereporthowserverkey

Problem

I have a deadlock report that tells me that there was a conflict involving

waitresource="KEY: 9:72057632651542528 (543066506c7c)"


and I can see this:



within the `` element.

I want to be able to find the actual value for the key (id = 12345, for example). What SQL statement would I need to use to obtain that information?

Solution

You have the hobt_id so the following query will identify the table:-

SELECT o.name
FROM sys.partitions p
INNER JOIN sys.objects o ON p.object_id = o.object_id
WHERE p.hobt_id = 72057632651542528


From that you can then run the following statement to identify the row in the table (if it still exists):-

SELECT %%LOCKRES%%,  *
FROM [TABLE NAME] WITH(INDEX(MyPrimaryKeyIndex))
WHERE %%LOCKRES%% = '(543066506c7c)'


Be careful with the above statement however, it will scan the target table so run in READ UNCOMMITTED and monitor your server.

Here's an article by Grant Fritchey about %%LOCKRES%% - http://www.scarydba.com/2010/03/18/undocumented-virtual-column-lockres/

And here's an article from my own blog about using %%LOCKRES%% to identify rows from an extended event:- https://dbafromthecold.wordpress.com/2015/02/24/identifying-blocking-via-extended-events/

Code Snippets

SELECT o.name
FROM sys.partitions p
INNER JOIN sys.objects o ON p.object_id = o.object_id
WHERE p.hobt_id = 72057632651542528
SELECT %%LOCKRES%%,  *
FROM [TABLE NAME] WITH(INDEX(MyPrimaryKeyIndex))
WHERE %%LOCKRES%% = '(543066506c7c)'

Context

StackExchange Database Administrators Q#106762, answer score: 15

Revisions (0)

No revisions yet.