Environment:
Sql server 2008 r2
Windows 7 64 bit
Windbg 64bit
What i already know
I can find the sql stmts in this transactions by running a server-side profiler trace and stopping it as soon as there is a deadlock. And then searching for the transaction Id in the trace files. But this is a brute force method and cannot always be done on a production environment.
I know i should send memory dump to microsoft and get then analyze it. But i want to find our if there is any hope to solve this without private symbols.
Problem:
I create a memory dump using extended events in sql server when 2 transactions deadlock ( lock_deadlock event).
I am manually creating this deadlock scenario via management studio. Lets say 1 of the deadlocked xaction has 2 sql statements in it.
begin tran
update tabl1 ... -- sql stmt 1
go
update tabl2 .. -- sql stmt 2
Now i find this thread in my memory dump and i am able to find out only my sql stmt 2 i.e "update tabl2".
Is there anyway i can look up all the sql stmts that thread had executed in the xaction i.e. in our case "update tabl1.." ?
I want to know what the thread had executed before in the same transaction. Since this xaction is not committed yet at the time of the dump, the values should be somewhere in the thread memory.
Please let me know if i dont make sense here. I have been after this problem for a while and
i want to know if this possible or not.
ADDITIONAL INFO
Background:
We have performance testing env, where we run 12 hour load tests. Next morning we analyze and find out a deadlock. Application executes 7-8 dml statements in a transaction ( we use hibernate ). Since sys.dm_exec_sql_text based will yield result only if its in the cache, we dont get the whole set of dml statements as we are analyzing it the next day (ps: i didnt even try this, when the problem was reported to me after 1 day)
How did we solve this problem today:
1. Setup server side trace
2. Setup event notification which triggers on deadlock and call a sp which stops the trace.
3. From extended event xml report or profiler, we find transaction id and look up the past statements corresponding to same.
How i thought i could solve this problem:
1. Trigger memory dump on extended event "lock_deadlock" with system id included.
2. Somehow try to find history in the thread corresponding to the system id.
Why memory dump:
Because this setup will cause least impact if i have to do it on production.
You are over engineering this. I don't claim to know all the intricate details of the thread memory but there is no reason for it to keep the statement last executed local, it doesn't need it to perform a rollback of the transaction, that is done using the log records from the transaction log if neccessary. Everything you need to figure out the cause of the deadlock is contained in the deadlock graph XML already. You definitely don't need a memory dump to figure it out. The TSQL execution stack for each of the processes is contained in the element under the process. For example:
All you have to do is take the sqlhandle and offset information from the frames and you can get the statements in the TSQL stack back out using sys.dm_exec_sql_text(). You won't be able to do this if you are trying to manually execute single statements one at a time to trigger the deadlock, since each stack is only going to have the single statement you executed in it.
UPDATE FROM ADDITIONAL INFO:
The alternative use of Event Notifications with internal queue activation to gather the additional information is the best way to do what you want done and it would be far less expensive than performing a memory dump. An activation stored procedure executes for an Event Notification to collect the data asynchronously, where the memory dump is performed synchronously on the firing thread in Extended Events as an Action.