![]() |
|
|
By: Jeremy Kadlec | Read Comments | Print Jeremy is the CTO @ Edgewood Solutions, co-founder of MSSQLTips.com and SQL Server MVP since 2009. Related Tips: More |
|
Problem
In specific SQL Servers databases, I have deadlock problems that often result in significant performance degradation. When the deadlocks occur frequently in my environment, the deadlocks often become a performance killer for the overall application. If the deadlocks become severe enough, I need to drop everything I am doing to manage the issue in order for the users to stay productive in the business application. If I could manage the deadlocks in an easier manner, that would be good motivation to move to SQL Server 2005. Does SQL Server 2005 have any new deadlock related features?
Solution
Let's first define a deadlock. A deadlock is a situation where 2 spids have data locked and cannot release their lock until the opposing spid releases their lock. Depending on the severity of the deadlock, meaning the amount of data that is locked and the number of spids that are trying to access the same data, an entire chain of spids can have locks and cause a number of deadlocks, resulting in a performance issue.
From SQL Server 2000 to 2005, the DEADLOCK_PRIORITY option has slightly changed offering some additional functionality. The DEADLOCK_PRIORITY option dictates how the spids are handled when a deadlock occurs. Before we jump into that new functionality, a few simple steps should be taken to address common deadlock issues:
The DEADLOCK_PRIORITY Option
As indicated earlier, the DEADLOCK_PRIORITY option dictates how the spids are handled when a deadlock occurs. The default deadlock priority in SQL Server 2000 and 2005 is NORMAL. SQL Server 2000 has two other settings of LOW and HIGH, whereas SQL Server 2005 has 21 settings based on a numeric priority. With this being said, SQL Server scans for deadlocks on a regular basis (i.e. every 5 seconds in SQL Server 2005) and the following logic is used to determine the victim of a deadlock:
During this scanning process is where the DEADLOCK_PRIORITY comes in handy. This configuration is set at run time, not at parse time. So once you have done the analysis for your application you will know which portions of code will either succeed or fail based on the DEADLOCK_PRIORITY. Below is an example of setting the DEADLOCK_PRIORITY in SQL Server 2005 for two different pieces of code to ensure you are able to control the outcome of the deadlock by ensuring the INSERT completes and the SELECT is the deadlock victim:
| SET DEADLOCK_PRIORITY LOW GO EXEC dbo.spGetAllOrders GO |
SET DEADLOCK_PRIORITY HIGH GO EXEC dbo.spInsertOrders GO |
Next Steps
| Share: | Share | Tweet |
|
![]() |
![]() |
Free SQL Server Learning |
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |