SQL Response - 1.3
Learning SQL Response - 1.3
Reducing deadlocks
Deadlocking occurs when two or more user processes have locks on separate objects and each process is trying to acquire a lock on the object that the other process has locked. When this happens, SQL Server resolves the deadlock by automatically aborting one process, the "victim" process, allowing the other processes to continue.
The aborted transaction is rolled back and an error message is sent to the user of the aborted process. Generally, the transaction that requires the least amount of overhead to roll back is the transaction that is aborted.
Deadlocks can cause a strain on a SQL Server's resources, especially CPU utilization.
Dealing with deadlocks
Most well-designed applications will resubmit the aborted transaction after receiving a deadlock message, which is then likely to run successfully. This process can affect performance, however. If the application has not been written to trap deadlock errors and automatically resubmit deadlocked transactions, users may receive deadlock error messages on their computer.
Tips on avoiding deadlocks
- Ensure the database design is properly normalized.
- Develop applications to access server objects in the same order each time.
- Do not allow any user input during transactions.
- Avoid cursors.
- Keep transactions as short as possible.
- Reduce the number of round trips between your application and SQL Server by using stored procedures or by keeping transactions within a single batch.
- Reduce the number of reads. If you do need to read the same data more than once, cache it by storing it in a variable or an array, and then re-reading it from there.
- Reduce lock time. Develop applications that obtain locks at the latest possible time, and release them at the earliest possible time.
- If appropriate, reduce lock escalation by using
ROWLOCKorPAGLOCK. - If the data being locked is not modified very frequently, consider using
NOLOCKto prevent locking. - If appropriate, use the lowest possible isolation level for the user connection running the transaction.
- Consider using bound connections.
Changing default deadlock behavior
When a deadlock occurs, by default, SQL Server chooses a deadlock "victim" by identifying which of the two processes will use the least resources to roll back, and then returns error message 1205. You can change the default behaviour using the following command:
SET DEADLOCK_PRIORITY { LOW NORMAL @deadlock_var }
LOWtells SQL Server that the current session should be the preferred deadlock victim, not the session that incurs the least rollback resources. The standard deadlock error message 1205 is returned.NORMALtells SQL Server to use the default deadlock method.@deadlock_varis a character variable specifying which deadlock method you want to use. Specify "3" for low, or "6" for normal.
This command is set at runtime for a specified user connection.
Links to more information
SQL Server 2008 Books Online: Detecting and Ending Deadlocks
http://msdn.microsoft.com/en-us/library/ms178104.aspx
Was this article helpful?
SQL Response
- Troubleshooting Computer Unreachable and Access Is Denied Error Messages
- SQL Response Security Setup
- Upgrading from Version 1.0 to 1.1 where the SQL Response Client and Alert Repository exist on the same machine
- Moving your Alert Repository Data
- Licensing SQL Response on a clustered SQL Server
- Server licenses may show "trial period has expired"
- How do I use the SQL Response client across domains?
- Where are the SQL Response data files stored?
- SQL Response client not connecting to Alert Repository
- The alert details are not recorded and SQL Response reports "Alert is still being written" when viewing an alert or multiple alerts
- Error when connecting to the Alert Repository using Windows 7
- Alert Repository transferring large amounts of data from the SQL Server
- Log files
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Response
- Migrating your Alert Repository from Windows 2000
- Tips for configuring SQL Response in your network environment
- SQL Response release notes - version 1.xx
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

What does SQL Response monitor?