Updated on 2024-08-29 GMT+08:00

Slow Query Logs

This section describes how to analyze slow query logs in a specified period. Slow Query Log displays a chart of SQL statements that are taking too long to execute and allows you to sort slow SQL statements by multiple dimensions, such as by user, host, or SQL template. It helps you quickly identify bottlenecks and improve instance performance.

Precautions

  • Enabling Collect Slow Query Logs is a must for slow query logs analysis. After it is enabled, DAS stores the slow query logs for analysis.
  • Slow query logs of free instances are retained for only one hour. For paid instances and free instances that you have subscribed to Intelligent O&M for, their slow query logs are retained for seven days by default and can be retained for up to 30 days. After the retention period expires, slow query logs are deleted.
  • You can enable the slow query logs function for a maximum of 10 free instances. There is no such a limit on paid instances and free instances that you have subscribed to Intelligent O&M for
  • For free instances, you can only view slow query logs generated in the latest hour.

Viewing Slow Query Logs

  1. Log in to the DAS console.
  2. Click in the upper left corner and select a region and project.
  3. Click in the upper left corner, and under Databases, click Data Admin Service.
  4. In the navigation pane, choose Intelligent O&M > Instance List.

    Alternatively, on the Overview page, click Go to Intelligent O&M.

  5. In the upper right corner of the Instance List page, search for instances by engine type, instance name, or instance IP.

    Figure 1 Searching for instances

  6. Locate the box containing your target instance and click Details.
  7. Choose SQL > Slow Query Logs.

    If Collect Slow Query Logs is not enabled, enable it as prompted in the Details area.

    Figure 2 Enabling slow query logs collection

    You can also click Log Settings in the upper right corner of the page to enable Collect Slow Query Logs.

  8. On the Slow Query Logs tab page, perform the following operations:

    • View slow queries over a specified period of time.

      Select a time range (last hour, last 3 hours, last 12 hours, or a user-defined time range which must be within one day) to view slow queries in the time range.

      Figure 3 Slow queries over time

      In the chart, you can hover your mouse at any point in time to view slow query logs or CPU usage.

      Above the chart, you can switch to another instance or node to view slow queries by instance or by node.

    • View slow query log details.
      View slow query log details in the lower part of the Slow Query Logs area. The details include the SQL statement, execution start time, database, client, user, execution duration, lock wait duration, and scanned and returned rows.
      Figure 4 Viewing slow query log details

      Click in the upper right corner of the Details area to export slow query log details to a specific OBS bucket. A maximum of 100,000 records can be exported.

      Figure 5 Exporting slow query log details

      After the details are exported, you can click Export History to view export records. You can also download the details to your local PC.

      Figure 6 Viewing export history

      Slow query log details of free instances cannot be exported. To use this function, set free instances as paid instances or subscribe to Intelligent O&M.

      Click Concurrency Control in the Operation column to create a concurrency control rule for the current SQL statement. For details, see SQL Statement Concurrency Control.

    • View slow query log statistics.
      Figure 7 Slow query log statistics

      In the template statistics list, click View Sample in the Operation column to view the sample of a SQL statement template.

      Click in the upper right corner of the Statistics area to export the SQL template to a specific OBS bucket. A maximum of 100,000 records can be exported.

      After the template is exported, you can click View Export List to view export records. You can also download the details to your local PC.

      Slow query log details of free instances cannot be exported. To use this function, set free instances as paid instances or subscribe to Intelligent O&M.

Slow Query Log Storage and Archiving

  • Slow query log storage

    Enabling Collect Slow Query Logs will allow DAS to store slow query logs for analysis.

    Slow query logs of free instances are retained for only one hour. For paid instances and free instances that you have subscribed to Intelligent O&M for, their slow query logs are retained for seven days by default and can be retained for up to 30 days. After the retention period expires, slow query logs are deleted.

    For paid instances and free instances that you have subscribed to Intelligent O&M for, you can click Log Settings in the upper right corner of the SQL page to set slow query log retention days.

    Figure 8 Setting storage duration for slow query logs

    Each paid instance and free instance that you have subscribed to Intelligent O&M for can use 5 GB of storage for slow query logs for free. Any storage used in excess of 5 GB will be billed on a pay-per-use basis.

  • Log archiving
    Slow query logs are automatically archived every 3 minutes. Alternatively, you can click Archive Now and then view the latest statistics.
    Figure 9 Log archiving

    Slow query logs generated in the last 10 days are archived.

    You can click Archive History to view archive records and click Download to download archived slow query logs to your local PC.

    Figure 10 Viewing archive history