Tracing Deadlocks

  • sivakumar-135209

    Valued Member

    Points: 74

    Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/skumar/tracingde

  • jean b

    Valued Member

    Points: 71

    DONT WORKED!!

    I just try it with the scripts bellow:

    DBCC TRACEON (3604)

    DBCC TRACEON (1204)

    GO

    begin transaction

       select top 1000000 cod_p   from p (tablockx)

       select top 1000000 p.cod_p,d.cod_d

       from p (tablockx)

       join d (tablockx) on d.cod_d=p.cod_p

    commit

    DBCC TRACEON (3604)

    DBCC TRACEON (1204)

    GO

    begin transaction

       select top 1000000 cod_d   from d (tablockx)

       select top 1000000 p.cod_p,d.cod_d

       from p (tablockx)

       join d (tablockx) on d.cod_d=p.cod_p

    commit

    I opnend 2 querys at query analyzer. I succeded to create a deadlock but its dont writed to error log.

     

    Jean, i need some help at lock timeout and deadlock.

     

     

  • Doctor Who

    Old Hand

    Points: 315

    I've got to ask a follow up question.  I am not certain when I should execute the

    DBCC TRACEON(3604)

    DBCC TRACEON(1294)

    commands.  For example, I've got a situation in which a deadlock occurs, but maybe only once every three or four weeks.  Do I just go into Query Analyzer, execute those commands now, and wait a few weeks until the problem shows up?  Or do I only execute those commands while the deadlock is in process?

     


    Doctor Who

  • rsherron

    SSC Veteran

    Points: 274

    This did the trick for me.  I had an instance where I was getting row level dead lock and needed to know how to get the table name based on the informaiton in the RID print out.  This lead me to the table I felt was causing the problem.

     

    THANK YOU!!!!!!!!!!!!!!!!

  • adrshen

    SSC-Addicted

    Points: 446

    thats is really excellent, but i would like to ask a question that its only track the information SPID (Server Process ID), how one can locate that this SPID was running which one query or stored procedure.because if SPID 65 generate the deadlock than , information track is only SPID and delete and after some time this SPID is assgned to other one

     

    waiting for a respose

     

  • adrshen

    SSC-Addicted

    Points: 446

    thats is really excellent, but i would like to ask a question that its only track the information SPID (Server Process ID), how one can locate that this SPID was running which one query or stored procedure.because if SPID 65 generate the deadlock than , information track is only SPID and delete and after some time this SPID is assgned to other one

     

    waiting for a respnose

     

  • sthornton

    Ten Centuries

    Points: 1223

    Once you have executed these commands, the error log starts filling up, so you may want to keep an eye on it from time to time and turn it off if its size is worrying you.

    You may want to turn it on for a while, and check the logs for "Deadlock encountered.... Printing deadlock information", then turn it off.

    To the Author:

    I'd like to know once you have identified what tables etc are part of the problem, how do you go about solving the problem in the first place?

  • Caroline_b

    SSC Enthusiast

    Points: 133

    I suppose I'm starting to develop a mild if somewhat exasperated affection for SQL Server, but then something like this comes along and annoys me all over again.  It's ludicrous to have to go to this amount of trouble to diagnose something as straightforward as a deadlock.  On DB2 on the mainframe (what a lot of your readers would regard as 'legacy') the thread which gets chucked out receives an error code (a -911 if my memory serves me correctly) and my all-time favourite error message: "This agent has been selected as the victim of a deadlock", which sounds like an instruction from the CIA   But no diagnosis is necessary, nor should it be.

    As for how to fix it, it's caused by 2 processes accessing and locking (exclusively) the same data in a different order:

    Process 1 has A and is waiting for B.  Process 2 has B and is waiting for A.  And there they will sit until kingdom come unless the system selects one to kill.

    A few things to try:

    reduce your lock size - table to page, page to row, and force it to stay there.  This has CPU and memory implications, so be careful.

    Change your clustering sequence on one of the tables involved (again, look at the bigger picture first).

    Ideally, design your apps to access things in the same order.  A lot of deadlocks are just the result of bad and inconsistent coding.

    If you have a real database hotspot, like a maximum key which gets both read and updated, try adding a very long field to the table, or a very high fill factor, so you only get one row per page.  If you are deadlocking at row level, rethink your design.

    Dinosaur tricks, but they might work.

    good luck!

    Caroline

     

     

  • anoel

    Old Hand

    Points: 338

    DBCC TRACEON (3604) & DBCC TRACEON (1204)  doesn't seem to work on SQL 2005.....I executed both, in that order on the server and watched the logs only to discover users were, in fact, receiving deadlock errors yet nothing was written to the log??

    Any suggestions?

  • VD

    Ten Centuries

    Points: 1149

    for SQL 2005 run

    DBCC TRACEON (1204, -1)

    DBCC TRACEON (1222, -1)

    -- to check the status

    DBCC TRACESTATUS(-1)

    for more information please check BOL.

    ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ed3e3e7-5080-4fa3-b79a-585470602bc2.htm

  • kevin mann

    Hall of Fame

    Points: 3894

    First off, kudoz to Siva! I have a more clear picture now that I can better read through the log. I definitely have a bit of reworking to do, though I do not have the luxury of always accessing objects in the same order all the time. But that's a story for another time. I was hoping I could get a lamen's explanation for deadlocks that read:

    "Transaction (Process ID ###) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.."

    It then prints out node after node of what appears to be chinese. From MSDN I gathered that it's attempting to reroute the Query somehow. Is this worse than the regular deadlocks discussed in the article? And what the heck is it trying to do?

  • Anatoliy-975407

    Grasshopper

    Points: 13

    Hello,

    Does somebody has idea how to identify rows that are involved in deadlock? I can trace deadlock information including SQL statements but I still can't see bonded values or any other information that helps to identify rows.

    Appreciate your attention!

    Thank you.

  • logicinside22

    SSCrazy Eights

    Points: 9617

    Hi Shiva

    Nice post about TF information..

    I would like to know Owner:0x0000000BA7ED6780 this shows in result of Trace flag output..

    And how i can know which table are locked from TF 1204 output.

    Aim to inspire rather than to teach.
    SQL Server DBA

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply