Lock analysis
Use the lock analysis feature to visually inspect and analyze database deadlocks. This feature helps you quickly identify and resolve these issues to ensure database stability.
Prerequisites
-
The target database engine is PolarDB for MySQL.
-
The target database instance is connected to Database Autonomy Service (DAS), and its connection status is Normal Access. For more information, see Connect a database instance to DAS.
Overview
The lock analysis feature supports multi-dimensional deadlock analysis for database instances.
The full deadlock analysis and other lock analysis features require Alibaba Cloud Managed Services (formerly Economy Edition) for DAS. This service is available only in specific databases and regions. For more information about how to enable this service, see Manage Alibaba Cloud Managed Services (formerly Economy Edition).
-
recent deadlock analysis: DAS analyzes the most recent deadlock log returned by
SHOW ENGINE INNODB STATUS. If multiple deadlocks occur, DAS analyzes only the most recent one. -
full deadlock analysis: DAS periodically analyzes error logs, parses deadlock information, and performs comprehensive deadlock analysis. DAS also supports viewing deadlock trends within a specified time range and the details of each deadlock.
-
other lock analysis: DAS uses data from
information_schemaandperformance_schemato analyze metadata locks and transaction blocking in the instance's current sessions.-
Metadata lock analysis: DAS derives lock wait relationships from data sources such as
information_schema.processlistand generates a corresponding relationship graph. -
Transaction blocking analysis: DAS analyzes transaction blocking relationships using
information_schema.processlist,information_schema.innodb_trx, and eitherinformation_schema.innodb_lock_waits(for MySQL 5.6 and 5.7) orperformance_schema.data_lock_waits(for MySQL 8.0). This analysis generates a corresponding relationship graph.
-
Database instance parameter limitations
To use a lock analysis feature, you must enable the required parameters for the target database instance.
|
Feature |
Required parameters |
|
recent deadlock analysis |
Enable the |
|
full deadlock analysis |
|
|
transaction blocking analysis in other lock analysis |
For PolarDB for MySQL 8.0 instances, you must enable the |
To modify database instance parameters, see Set cluster and node parameters.
Precautions
The deadlock analysis feature cannot be used 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 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 Analysis.
-
On the Lock Analysis page, view or diagnose recent deadlocks in the database instance.
-
Recent deadlock analysis
-
On the Recent Deadlock Analysis tab, click Create Analysis Task. DAS analyzes the most recent deadlock log from the output of
SHOW ENGINE INNODB STATUS. -
Select a time range to view the deadlock diagnosis results. In the Details column of a diagnosis result, click View Details to see the details.
-
-
Full deadlock analysis
On the Full Deadlock Analysis tab, view deadlock trends and the details of each deadlock within a specified time range.
-
Other lock analysis
-
On the Other Lock Analysis tab, click Create Analysis Task. DAS uses data from
information_schemaandperformance_schemato analyze metadata locks and transaction blocking in the current sessions of the database instance in real time. -
Select a time range to view the diagnosis results.
-
Click the
icon before a diagnosis result to view the lock analysis statistics. -
In the Actions column of the statistics, click View Details to view detailed diagnosis results and the lock analysis relationship graph.
Hover over a session to view its associated lock-wait relationships. Click a session to view its details.
-
-
-
What to do next
When a deadlock or transaction blocking occurs on your database instance, you can use the information such as the thread IDs obtained after the lock analysis to analyze the execution of related transactions on the SQL Explorer and Audit page. This helps identify the cause of lock waits. For example, after a transaction is started and specific data rows are updated, the data rows are locked. If the execution of the transaction lasts for an extended period of time and the transaction is not explicitly or implicitly committed or rolled back, subsequent sessions or transactions that update the same data rows will enter the LOCK WAIT state.