This topic describes how to use the lock analysis feature of Database Autonomy Service (DAS) to analyze database deadlocks. Deadlock analysis covers recent deadlock analysis and full deadlock analysis.
In this topic, the data presented in figures is used as test data and is for reference only. In real-world scenarios, parameters such as thread IDs and SQL statements vary based on the actual database environments.
Prerequisites
Your database instance runs one of the following database engines:
Recent deadlock analysis:
ApsaraDB RDS for MySQL
Self-managed MySQL database
PolarDB for MySQL
PolarDB-X 2.0
Full deadlock analysis:
ApsaraDB RDS for MySQL
PolarDB for MySQL
Your database instance is connected to DAS and is in the Normal Access state. For more information, see Connect a database instance to DAS.
DAS Economy Edition or DAS Enterprise Edition is enabled.
ImportantDAS Economy Edition and DAS Enterprise Edition are available only in specific regions. For more information, see the Supported databases and regions section of the "DAS editions and supported features" topic.
For more information about how to enable DAS Economy Edition or DAS Enterprise Edition, see the Enable DAS Economy Edition and DAS Enterprise Edition section of the "Enable and manage DAS Economy Edition and DAS Enterprise Edition" topic.
Recent deadlock analysis
Parameter settings: You must set the
innodb_deadlock_detect
parameter to ON.For more information about how to modify the parameters of a database instance, see one of the following topics based on the database engine of your database instance:
ApsaraDB RDS for MySQL: Modify instance parameters
PolarDB for MySQL: Configure cluster and node parameters
Data analysis: DAS analyzes the most recent deadlock log in the output of the
SHOW ENGINE INNODB STATUS
statement.
If multiple deadlocks have occurred, DAS analyzes only the most recent deadlock and retains the deadlock data.
Procedure
Log on to the DAS console.
In the left-side navigation pane, click Instance Monitoring.
On the page that appears, find the database instance that you want to manage and click the instance ID. The instance details page appears.
In the left-side navigation pane, click Lock Analysis. On the Lock Analysis page, click the Recent Deadlock Analysis tab.
Then, click Create Analysis Task to analyze the most recent deadlock.
View details
Specify a time range to view deadlock analysis results.
On the Recent Deadlock Analysis tab, click View Details in the Details column of the analysis task.
You can view the deadlock details by using one of the following methods:
View: displays the deadlock details by using the visualized deadlock relationship. You can click the corresponding transaction tile to view the transaction details at the bottom.
List: compares the details of lock-holding transactions in a list.
Log: displays the original deadlock log (LATEST DETECTED DEADLOCK) in the output of the
SHOW ENGINE INNODB STATUS
statement.
Deadlock analysis by using SQL Explorer and Audit
In the left-side navigation pane, click SQL Explorer and Audit. On the Audit tab, click Enable Advanced Query.
Select a time range that covers the time when the deadlock occurred and enter the thread ID identified from the recent deadlock analysis to query the SQL statements executed by the transaction.
Transaction 1 for the preceding sample
Transaction 2 for the preceding sample (rolled back)
Full deadlock analysis
Parameter settings: You must set the
innodb_deadlock_detect
andinnodb_print_all_deadlocks
parameters to ON. If you use an ApsaraDB RDS for MySQL instance, set thelog_error_verbosity
parameter to 3.For more information about how to modify the parameters of a database instance, see one of the following topics based on the database engine of your database instance:
ApsaraDB RDS for MySQL: Modify instance parameters
PolarDB for MySQL: Configure cluster and node parameters
Data analysis: DAS parses the deadlock information that is displayed in the instance error log on an hourly basis, and collects statistics on the trend of the number of deadlocks and the details of each deadlock.
Cooldown period: If DAS Economy Edition or DAS Enterprise Edition is enabled for an instance but the required parameters are disabled, the instance is cooled down for 12 hours. During the cooldown period, DAS does not perform deadlock analysis. If you enable the required parameters during the cooldown period, DAS reschedules the analysis task after the cooldown period. Example:
If DAS detects that a required parameter is disabled for the instance that has an analysis task scheduled at 11:12, the task is cooled down for 12 hours. DAS reschedules the full deadlock analysis task for the instance at 23:12. If the parameter is still disabled after the first cooldown period, the scheduled task continues to be cooled down for another 12 hours. If the parameter is enabled before 23:12, the current cooldown period becomes invalid after 23:12. Then, the scheduled task executes the full deadlock analysis on an hourly basis until the parameter is disabled for the instance or DAS Economy Edition or DAS Enterprise Edition is disabled for the instance.
You cannot use the full deadlock analysis feature to analyze deadlocks that contain the following information: TOO DEEP OR LONG SEARCH IN THE LOCK TABLE WAITS-FOR GRAPH, WE WILL ROLL BACK FOLLOWING TRANSACTION.
Procedure
Log on to the DAS console.
In the left-side navigation pane, click Instance Monitoring.
On the page that appears, find the database instance that you want to manage and click the instance ID. The instance details page appears.
In the left-side navigation pane, click Lock Analysis. On the Lock Analysis page, click the Full Deadlock Analysis tab.
The full deadlock analysis feature automatically analyzes the deadlock information displayed in the instance error log on an hourly basis, collects statistics on the number of deadlocks, and plots the Deadlock Trend chart at the top of the page. Specify a time range to view the deadlock trend.
View details
On the Full Deadlock Analysis tab, click View Details in the Details column of the deadlock analysis task.
You can view the deadlock details by using one of the following methods: view, list, and log. The log contains the deadlock error information. Views and lists for full deadlock analysis are displayed in the same formats as views and lists for recent deadlock analysis. For more information, see the "View details" subsection of the Recent deadlock analysis section in this topic.
Deadlock analysis by using SQL Explorer and Audit
The procedure of using SQL Explorer and Audit for full deadlock analysis is the same as the procedure of using SQL Explorer and Audit for recent deadlock analysis. For more information, see the "Deadlock analysis by using SQL Explorer and Audit" subsection of the Recent deadlock analysis section in this topic.