All Products
Search
Document Center

Database Autonomy Service:Deadlock analysis

Last Updated:Jul 04, 2024

Database Autonomy Service (DAS) provides the deadlock analysis feature that allows you to view and analyze deadlocks in a database. This helps you identify and troubleshoot deadlocks with ease and ensure database stability.

Prerequisites

  • Your database instance runs one of the following database engines:

    • ApsaraDB RDS for MySQL

    • Self-managed MySQL

    • PolarDB for MySQL

    • PolarDB-X 2.0

  • Your database instance is connected to DAS and is in the Normal Access state. For more information, see Connect a database instance to DAS.

Features

The deadlock analysis feature allows you to perform a deadlock analysis on a database instance in multiple dimensions.

Important

The full deadlock analysis and other deadlock analysis features are supported only for ApsaraDB RDS for MySQL and PolarDB for MySQL instances. To use these features for a database instance, you must enable DAS Cost-efficient Edition or DAS Enterprise Edition for the database instance. DAS Cost-efficient Edition and DAS Enterprise Edition are available only in specific regions. For more information, see the Supported databases and regions section of the "Editions and supported features" topic. For more information about how to enable DAS Cost-efficient Edition or DAS Enterprise Edition, see the Enable DAS Enterprise Edition section of the "Enable and manage DAS Enterprise Edition" topic.

  • Recent deadlock analysis: DAS analyzes the most recent deadlock logs in the returned results of the SHOW ENGINE INNODB STATUS statement. If multiple deadlocks have occurred, DAS analyzes only the most recent deadlock.

  • Full deadlock analysis: DAS analyzes error logs on a regular basis, parses the deadlock information, and then performs comprehensive deadlock analysis. DAS also allows you to view the deadlock trends within a specific time range and view the details of each deadlock.

  • Other deadlock analysis: DAS analyzes the metadata locks and blocked transactions in the current sessions of your database instance in real time based on the data in the information_schema and performance_schema databases.

    • Metadata lock analysis: DAS deduces the lock wait relationships and generates the corresponding diagram based on the data in tables such as the information_schema.processlist table.

    • Transaction blocking analysis: DAS analyzes the transaction blocking relationships and generates the corresponding diagram based on the data in the information_schema.processlist, information_schema.innodb_trx, and information_schema.innodb_lock_waits or performance_schema.data_lock_waits tables. Data in the information_schema.innodb_lock_waits table is used for database instances that run MySQL 5.6 or MySQL 5.7, and data in the information_schema.innodb_lock_waits table is used for database instances that run MySQL 8.0.

Parameter settings

To use a deadlock analysis feature for a database instance, you must specify the corresponding parameters of the database instance. The following table describes the parameter settings required for different deadlock analysis features.

Deadlock analysis feature

Required parameter settings

Recent deadlock analysis

Set the innodb_deadlock_detect parameter to ON.

Full deadlock analysis

  • Set the innodb_deadlock_detect parameter to ON.

  • Set the innodb_print_all_deadlocks parameter to ON. If the database instance is an ApsaraDB RDS for MySQL instance, you must also set the log_error_verbosity parameter to 3.

Transaction blocking analysis in other lock analysis

If the database instance is an ApsaraDB RDS for MySQL 8.0 instance or a PolarDB for MySQL 8.0 cluster, you must set the performance_schema 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:

Usage notes

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

  1. Log on to the DAS console.

  2. In the left-side navigation pane, click Instance Monitoring.

  3. On the page that appears, find the database instance that you want to manage and click the instance ID. The instance details page appears.

  4. In the left-side navigation pane of the instance details page, click Deadlock Analysis.

  5. On the Deadlock Analysis tab, view or diagnose the detected deadlocks.

    • Recent Deadlock Analysis

      • On the Recent Deadlock Analysis tab, click Create Analysis Task. DAS analyzes the most recent deadlock logs in the returned results of the SHOW ENGINE INNODB STATUS statement.

      • Specify a time range to view the diagnostics results within the specified time range. Find a task and click View Details in the Details column to view the details of the diagnostics results.

    • Full Deadlock Analysis

      On the Full Deadlock Analysis tab, view the deadlock trends and the details of each deadlock within the specified time range.

    • Other Deadlock Analysis

      • In the Other Deadlock Analysis section, click Create Analysis Task. DAS analyzes the metadata locks and blocked transactions in the current sessions of your database instance in real time based on the data in the information_schema and performance_schema databases.

      • Specify a time range to view the diagnostics results within the specified time range.

        1. Find a task and click the image icon in front of the task to view the statistics information about the deadlock analysis.

        2. Click View Details in the Actions column to view the details of the diagnostics results and the deadlock analysis diagram.

          Move the pointer over a session. You can view the lock wait diagram of the session. Click the session to view the session details.

What to do next

If a deadlock occurs in a database instance, you can use the information that you obtain by using the deadlock analysis feature, such as the thread ID of the transaction, to analyze the transaction on the SQL Explorer tab. This helps you identify the cause of the deadlock. For example, after a transaction is started and a specific number of data rows are updated, the data rows are locked. If 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 will enter the LOCK WAIT state when the same number of data rows are updated.