When do you start troubleshooting a SQL Server 2005/2008 deadlocks and how? The alert is turned on SSMS via SQL Server performance condition alert, objects->SQLServer:Locks, Counter->Lock Waits/Sec, Instance:_Total, alert if counter: rises above value 3. Is this a proactive way of monitoring it? What is the acceptable value? I would highly apprecate your help. Thank you!!!
5 Answers
You can use Event Notifications to get notified whenever a deadlock happens on the server:
See:
- Immediate deadlock notifications without changing existing code by Mladen Prajdić
- Using SQL Profiler to Resolve Deadlocks in SQL Server by Jonathan Kehayias
Additional links:
- The Anatomy of a Deadlock - Jonathan Kehayias
- Anatomy of a Deadlock - Part Deux - Jonathan Kehayias
- Read/Write deadlock - by Remus Rusanu
- 2,655
- 19
- 14
The first thing to do is look at the deadlock graph and see exactly what's going on. Then you can consider your options, which usually boil down to a) modify the application to standardize on an order of locking objects (e.g. if possible given the application logic, make a convention with your developers to always lock tables in alphabetical order) or b) see if you are really operating at the appropriate isolation level in each transaction.
I would go with automatic server side tracing of 2 main issues:
long queries (you establish duration that's long for your environment)
deadlocks - check Deadlock graph and Lock:Deadlock chain
You will get trace files every day and you can monitor the action - see if some scheduled event is causing issues. You can see more details about profiling production in this question: Using SQL Profiler on a database that's in production.
Try setting traceflags, as desribed in this books online article: http://msdn.microsoft.com/en-us/library/ms178104%28SQL.90%29.aspx
DBCC TRACEON(1204) DBCC TRACEON(1222) -- new to SQL 2005 DBCC TRACEON(-T1222)
- 7,141
- 4
- 38
- 58
System Center Operations Manager (SCOM) with the SQL Server Management Pack can alert on deadlocks if you enable logging for message 1205. You can enable it with the following SQL query: EXEC sp_altermessage 1205, 'WITH_LOG', 'true'.
Also, see my answer to "Why isn't the objectname and indexname populated in deadlock graph?" for a PowerShell script I wrote that will pull deadlock information from the event buffer and write the deadlock graphs as xdl files that can be opened in SQL Management Studio 2012 or higher or viewed in notepad to see more detail.