SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Deadlocks


SQL Deadlocks

Author
Message
bugg
bugg
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4305 Visits: 1049
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.
anthony.green
anthony.green
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62362 Visits: 8587
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.



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
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


GilaMonster
GilaMonster
SSC Guru
SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)

Group: General Forum Members
Points: 545942 Visits: 47728
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, MVP, M.Sc (Comp Sci)
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


bugg
bugg
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4305 Visits: 1049
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
bugg
bugg
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4305 Visits: 1049
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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)

Group: General Forum Members
Points: 545942 Visits: 47728
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, MVP, M.Sc (Comp Sci)
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


GilaMonster
GilaMonster
SSC Guru
SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)SSC Guru (545K reputation)

Group: General Forum Members
Points: 545942 Visits: 47728
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, MVP, M.Sc (Comp Sci)
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


Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35648 Visits: 11933
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.
bugg
bugg
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4305 Visits: 1049
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.
bugg
bugg
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4305 Visits: 1049
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 Unsure
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search