Database Autonomy Service (DAS) provides the Lock Optimization feature for ApsaraDB RDS for SQL Server. You can use this feature to view deadlocks and their details in your database instance.
Prerequisites
-
This feature is not supported for ApsaraDB RDS for SQL Server 2008 R2 instances that use cloud disks.
-
The instance must be in one of the following regions:
China (Hangzhou), China (Shanghai), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Hohhot), China (Ulanqab), China (Shenzhen), China (Heyuan), China (Guangzhou), China (Chengdu), China (Hong Kong), Singapore, and UAE (Dubai).
Background information
When a transaction modifies a resource, it applies a lock to prevent other transactions from changing it, which ensures data consistency.
A deadlock typically occurs when multiple transactions compete for resources. For example, Transaction A locks Resource A and tries to modify Resource B, while Transaction B locks Resource B and tries to modify Resource A. This circular dependency causes a deadlock, as each transaction waits for the other to release its lock. The system then automatically terminates the session with the lowest rollback cost (the victim session), causing its task to fail. The following figure illustrates this scenario.

Deadlock types
The Deadlock page displays statistics for the following five deadlock types:
-
KeyDeadlock
-
ObjectDeadlock
-
RIDDeadlock
-
PageDeadlock
-
CompileDeadlock
Lock modes
When a transaction accesses a resource, it uses different lock modes (LockMode) based on the access type. These include:
-
Shared lock (S): Allows a resource to be read but not modified while the lock is active.
-
Update lock (U): Prevents other transactions from acquiring an exclusive lock on a resource, signaling an intent to modify it. This lock is typically used to avoid deadlocks that can occur when multiple sessions try to read, lock, and then update a resource.
-
Exclusive lock (X): Prevents other transactions from accessing the resource.
Procedure
Log on to the DAS console.
In the navigation pane on the left, click .
Find the target instance and click the instance ID to open the instance details page.
-
In the left-side navigation pane, click Lock Optimization > DeadLock.
-
On the DeadLock page, review the deadlock details.
Page overview
-
The Deadlock Count Overview section displays statistics for preset time ranges, including Last 24 Hours, Last 7 Days, Last 14 Days, and Last Month.
-
Deadlock Trend

This chart displays the types of deadlocks that occurred over a specific time range. You can perform the following operations:
-
Select a Start time and an End time, and then click Search to display deadlock information for the specified time range.
NoteThe time range cannot exceed 30 days.
-
Click Last 24 Hours, Last 7 Days, or Last Month to quickly query deadlock information for the selected time range.
-
Hover over a point on the trend chart to view the types and number of deadlocks that occurred at that time.
-
Click the
icon in the upper-right corner of the trend chart to switch the chart's display style or download the chart.
-
-
Deadlock Details
Click the
icon to the left of a record to expand the record and view the details of the interdependent sessions. The details include the following information:-
LastTranStarted: The time when the transaction started.
-
SPID: The ID of the session that started the transaction.
-
IsVictim: Indicates whether the session was the deadlock victim.
NoteSQL Server resolves deadlocks by using an internal thread to periodically detect them. After a deadlock is detected, SQL Server terminates the session with the lower rollback cost among the involved sessions. For example, a SELECT statement usually costs less than an UPDATE statement, so SQL Server prioritizes terminating the session that runs the SELECT statement.
-
LogUsed: The size of the log generated by the session. Unit: bytes.
-
LockMode: The lock mode. For more information, see Lock modes.
-
WaitResourceDesc: A description of the resource that the current transaction is waiting for.
-
ObjectOwned: The object locked by this session.
-
ObjectRequested: The object that the session is attempting to lock.
-
WaitResource: The resource that the transaction is waiting for.
-
HostName: The hostname of the client that initiated the transaction.
-
LoginName: The account name used for the transaction.
-
Status: The current status of the transaction.
-
ClientApp: The name of the client application used for the transaction.
-
SQLText: The details of the SQL statement.
NoteClick the SQL statement to open it in a new window. Click Click to Copy to copy the statement for troubleshooting or analysis.
Click any row to display the corresponding deadlock diagram below.
-
-
Deadlock Diagram

This diagram displays the relationship between the sessions involved in the deadlock and provides details about the locked resources. Click Download to download an XDL file. This file contains the complete details of the current deadlock and can be opened with a SQL Server Management Studio (SSMS) client.