Slow query logs

Updated at:

Slow SQL queries can significantly affect database stability. When a database experiences issues such as high workloads or performance jitters, the first step for database administrators (DBAs) or developers is to check for slow queries. Database Autonomy Service (DAS) provides a slow query log analysis feature that collects and analyzes SQL statements whose execution time exceeds a specified threshold. This feature helps you quickly identify and resolve database performance issues to improve system stability and reliability.

Background information

The database kernel generates slow query logs. Configuration parameters and thresholds vary by database engine. For details, see the official documentation for your database engine.

Procedure

  1. Log on to the DAS console.

  2. In the navigation pane on the left, click Intelligent O&M Center > Instance Monitoring .

  3. Find the target instance and click the instance ID to open the instance details page.

  4. In the left-side navigation pane, click Request Analysis > Slow Logs.

  5. Select a time range to view the Slow Log Trend, Event Distribution, Slow Log Statistics, and Slow Log Details.

    • In the Nodes section, view the number of slow requests for each node.

    • In the Event Distribution area, you can query for slow log events within a specified time range. Click an event to view its details.

    • In the Slow Log Trend chart, you can select a point in time to view the Slow Log Statistics and Slow Log Details for that time.

      Note

      If a slow SQL statement is too long to be fully displayed, you can hover the mouse pointer over the statement to view the complete SQL statement in a pop-up box.

    • On the Slow Query Log Statistics and Slow Query Log Details tabs, you can click image to save the slow query log information to your computer.

    • You can click image to go to the OpenAPI Explorer console. The currently selected and entered parameters are automatically carried over for API debugging.

    • In the Slow Log Statistics area:

      • Above the list, you can select filter conditions to filter the data. The available filter conditions vary depending on the database engine.

      • Click the target SQL ID column to view correlations and a detailed list that includes user distribution, client distribution, and metric trends.

      • In the Actions column of the target SQL template, click Optimize. In the SQL Diagnostic Optimization dialog box that appears, view the SQL diagnosis results.

        If you accept the diagnostic suggestion, click Copy in the upper-right corner of the page and paste the optimized SQL statement into your database client or DMS to execute it. If you do not accept the suggestion, click Cancel to end the diagnosis.

        Note

        DAS performs SQL diagnosis based on the complexity of the SQL statement, the data volume of the corresponding table, and the database payload. The diagnostic suggestion may take more than 20 seconds to be returned. After the diagnosis is complete, the diagnostics engine provides a diagnosis result, an optimization suggestion, and the expected optimization benefits. You can decide whether to accept the suggestion based on the diagnosis result.

      • In the Actions column of the target SQL template, click Throttling. On the SQL Throttling page, configure the throttling parameters to apply rate limiting to the target SQL statement. For more information, see SQL throttling.

      • For a PolarDB for MySQL database instance, in the Actions column of the target SQL template, click IMCI to view the documentation for In-Memory Column Index (IMCI).

        Note
        • The IMCI button is displayed if a PolarDB for MySQL database instance does not have an In-Memory Column Index node, the Max Execution Time of a slow query log exceeds 20 seconds, and the Max Scanned Rows exceeds 200,000.

        • For complex queries with large data volumes, you can use In-Memory Column Index (IMCI) to improve query performance.

    • In the Slow Log Details area, you can also click Optimize and Throttling in the Actions column for a target SQL statement to perform SQL Diagnostic Optimization and SQL Throttling.