All Products
Search
Document Center

PolarDB:Slow SQL queries

Last Updated:Jun 18, 2025

PolarDB for PostgreSQL (Compatible with Oracle) provides the slow SQL analysis feature. This feature allows you to view slow log trends and statistics. You can also obtain the diagnostic results and suggestions on how to fix slow SQL queries.

Procedure

  1. Log on to the PolarDB console. In the left-side navigation pane, click Clusters. In the upper-left corner, select the region of the cluster. In the cluster list, find the cluster and click its ID to go to the Basic Information page.

  2. In the left-side navigation pane, choose Diagnostics and Optimization > Slow SQL.

  3. On the Slow Log Analysis tab, specify a time range and view the Slow Query Log Trends, Event Distribution, Slow Query Log Statistics, and Slow Query Log Details within the specified time range.

    Note

    When you specify the time range, the end time must be later than the start time, and the interval between the start time and the end time cannot exceed 24 hours. You can query slow query logs within the previous month.

    • In the Slow Query Log Trends section, you can click a point in time in the trend chart and view the statistics and details of the slow query logs at the point in time.

      Note

      If the content of an SQL statement is not completely displayed due to length limits of the GUI, you can move the pointer over the SQL statement to view the complete content.

    • Select the desired node from the Node ID drop-down list to view the number of slow queries on the node.

    • In the Event Distribution section, perform the following operation:

      You can query slow query log events within the specified time range. Click an event to view its details.

    • You can click image to download slow query logs to your computer.

    • Click image to populate the selected and entered parameters to the OpenAPI console for API debugging.

    • On the Slow Query Log Statistics tab, find the SQL template that you want to manage and click Details in the Actions column. In the Slow Log Sample dialog box, view the slow query log sample of the SQL template.

    • On the Slow Query Log Details tab, find the SQL statement that you want to manage and click Optimize or Throttling in the Actions column to perform SQL diagnostic optimization or SQL throttling.

FAQ

Q: Why is the execution completion time of SQL statements recorded in slow query logs different from the actual execution completion time of the SQL statements?

A: This issue usually occurs when the time zones recorded in the slow query logs are modified by the executed SQL statements. The execution completion time of an SQL statement varies with the time zone recorded in slow query logs at the following levels: session level, database level, and system level. If a time zone is specified for the database, the execution completion time of an SQL statement is recorded based on the time zone of the database. Otherwise, the execution completion time of an SQL statement is recorded based on the time zone of the system. If an SQL statement modifies the time zone at the session level, the time zone recorded in slow query logs may not be properly converted.

Related API operations

Operation

Description

DescribeSlowLogRecords

Queries the details of slow logs for a cluster.

DescribeDBClusterAuditLogCollector

Queries whether SQL data collector is enabled for a cluster.

ModifyDBClusterAuditLogCollector

Enables or disables SQL data collector for a cluster.