Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

SQL Deadlocks Expand / Collapse
Author
Message
Posted Tuesday, January 22, 2013 8:40 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 200, Visits: 701
In my production database I'm getting a few deadlocks between updates and selects. Where the selects are being killed off.

I'm trying to work out the best way to eliminate these.

After a bit of research I don't really want to use SNAPSHOT ISOLATION or READ_COMMITTED_SNAPSHOT as this approach would require downtime to alter the database and possibly loads of testing and might be overkill for my needs and unnecessary overload on my temp db.

I also don't really want to go down the (nolock) route.

What would be the best way to approach this? Exclusive locks on the updates?

Any insight into dealing with deadlocks would be greatly appreciated.
Post #1410074
Posted Tuesday, January 22, 2013 8:44 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 8, 2014 1:45 AM
Points: 5,221, Visits: 5,120
Do you have traceflag 1222 enabled?

If so can you post the deadlock graph from the error log

If not run

DBCC TRACEON (1222, -1)

and then post the graphs once a deadlock has occured.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1410078
Posted Tuesday, January 22, 2013 8:58 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
bugg (1/22/2013)
Any insight into dealing with deadlocks would be greatly appreciated.


In general:
Optimise the queries. If that doesn't fix the problem use one of the row versioning-based isolation levels



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1410087
Posted Tuesday, January 22, 2013 9:02 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 200, Visits: 701
anthony.green (1/22/2013)
Do you have traceflag 1222 enabled?

If so can you post the deadlock graph from the error log

If not run

DBCC TRACEON (1222, -1)

and then post the graphs once a deadlock has occured.


Started profiler now. Will update once ive captured a deadlock
Post #1410092
Posted Tuesday, January 22, 2013 9:04 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 200, Visits: 701
GilaMonster (1/22/2013)
bugg (1/22/2013)
Any insight into dealing with deadlocks would be greatly appreciated.


In general:
Optimise the queries. If that doesn't fix the problem use one of the row versioning-based isolation levels



Thanks Gila, I'm going to try using Rowlock with the update commands and see if that clears the locks.
Post #1410093
Posted Tuesday, January 22, 2013 9:04 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
bugg (1/22/2013)
anthony.green (1/22/2013)
Do you have traceflag 1222 enabled?

If so can you post the deadlock graph from the error log

If not run

DBCC TRACEON (1222, -1)

and then post the graphs once a deadlock has occured.


Started profiler now. Will update once ive captured a deadlock


Profiler? That traceflag writes the deadlock graph into the SQL error log, not a trace event.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1410095
Posted Tuesday, January 22, 2013 9:06 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
bugg (1/22/2013)
GilaMonster (1/22/2013)
bugg (1/22/2013)
Any insight into dealing with deadlocks would be greatly appreciated.


In general:
Optimise the queries. If that doesn't fix the problem use one of the row versioning-based isolation levels



Thanks Gila, I'm going to try using Rowlock with the update commands and see if that clears the locks.


Optimise your queries, don't mess with locking hints unless you really understand what you're doing and why and have optimised as much as possible.
You do realise that a row lock hint means more chance of lock escalation (to table), not less?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1410096
Posted Tuesday, January 22, 2013 9:07 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:38 AM
Points: 3,110, Visits: 11,528
bugg (1/22/2013)

...
After a bit of research I don't really want to use SNAPSHOT ISOLATION or READ_COMMITTED_SNAPSHOT as this approach would require downtime to alter the database and possibly loads of testing and might be overkill for my needs and unnecessary overload on my temp db.
...


You do not need to take the database offline to enable SNAPSHOT ISOLATION, but you do need to for READ_COMMITTED_SNAPSHOT.

Post #1410097
Posted Tuesday, January 22, 2013 9:21 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 200, Visits: 701
GilaMonster (1/22/2013)
bugg (1/22/2013)
anthony.green (1/22/2013)
Do you have traceflag 1222 enabled?

If so can you post the deadlock graph from the error log

If not run

DBCC TRACEON (1222, -1)

and then post the graphs once a deadlock has occured.


Started profiler now. Will update once ive captured a deadlock


Profiler? That traceflag writes the deadlock graph into the SQL error log, not a trace event.


Ahh right, I'm running SQL profiler and have set it up to watch for deadlocks and produce deadlock graphs.
Post #1410103
Posted Tuesday, January 22, 2013 9:24 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 200, Visits: 701
GilaMonster (1/22/2013)
bugg (1/22/2013)
GilaMonster (1/22/2013)
bugg (1/22/2013)
Any insight into dealing with deadlocks would be greatly appreciated.


In general:
Optimise the queries. If that doesn't fix the problem use one of the row versioning-based isolation levels



Thanks Gila, I'm going to try using Rowlock with the update commands and see if that clears the locks.


Optimise your queries, don't mess with locking hints unless you really understand what you're doing and why and have optimised as much as possible.
You do realise that a row lock hint means more chance of lock escalation (to table), not less?


Nope I did not realize that! I thought it was specific to the row being updated
Post #1410105
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse