Updated on 2023-12-13 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

  • Toggle on Enable DAS Slow Query Log . After that, DAS automatically stores slow query logs for analysis.
  • Slow query logs of free instances are retained for only one hour while those of paid instances 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.
  • For free instances, you can only view slow query logs generated in the latest hour.

Viewing slow query logs

  1. Log in to the management 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. In the upper right corner of the page, click Go to Old Edition.

    Figure 2 Accessing Intelligent O&M of the old version

  8. Choose SQL > Slow Query Logs.
  9. Select a time range and view trends, statistics, and details of the slow query logs generated within the time range.

    • Log trends
      Figure 3 Log trends

      In the trends graph, 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.

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

      Click Export to export slow query log details to a specific OBS bucket. After the details are exported, you can click Export History to view export records. You can also download the details to your local PC for view.

      Figure 5 Exporting slow query log details

      This function is available to only paid instances.

      Locate the SQL template you want to diagnose and click Diagnose in the Operation column.

    • Statistics
      Figure 6 Slow query log statistics

      Click Sample in the Operation to view the sample of the SQL template.

      On the Statistics page, click Export to export slow query logs to a specific OBS bucket. Then you can click Export History to view export records. You can also download the exported slow query logs to your local PC.
      Figure 7 Exporting slow query logs

      Exporting and viewing slow query logs are available to only paid instances.

Slow Query Log Storage and Archiving

  • Slow query log storage

    Toggling on Enable DAS Slow Query Log will allow DAS to automatically store slow query logs for analysis.

    Slow query logs of free instances are retained for only one hour while those of paid instances 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, you can click Set Storage Duration for Slow Query Logs to set storage duration as required.

    Figure 8 Setting storage duration for slow query logs

    Each paid instance 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 three minutes. Alternatively, you can click Generate Latest Log File and then view the latest statistics.
    Figure 9 Log archiving

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

    You can also download archived slow query logs to your local PC.

Deleting Slow Query Logs

On the Slow Query Logs tab, you can delete all slow query logs or logs generated in a specific period.

Figure 10 Deleting slow query logs

Deleted slow query logs cannot be recovered. Exercise caution when performing this operation.