Updated on 2023-12-13 GMT+08:00

SQL Explorer

After Collect All SQL Statements is enabled, you can gain a comprehensive insight into SQL statements on the SQL Explorer page. Top SQL helps you locate exceptions.

SQL Explorer can record all SQL statements executed on your instance and enables you to analyze and search for the tables that are accessed and updated the most frequently and the SQL statements that have the longest lock wait.

Precautions

  • After Enable DAS SQL Explorer is toggled off, new SQL statements will not be collected anymore and the collected SQL data will be deleted.
  • Logs of all SQL statements executed on free instances can be retained for only one hour while those for paid instances can be retained for seven days by default and for up to 30 days as a maximum. After the retention period expires, the logs are deleted automatically.
  • SQL Explorer cannot record all data. As for RDS for PostgreSQL, it has the following constraints:

    SQL Explorer is limited by the memory buffer, so some data may not be recorded when a buffer overrun occurs, for example, when the QPS is over 1000 or the usage of resources such as CPUs or memory becomes too high.

    Any SQL statement that exceeds 4,096 bytes by default will be discarded.

    SQL Explorer is available to only RDS for PostgreSQL instances of the following versions:

    • Major version: 14; minor version: 14.4 or later
    • Major version: 13; minor version: 13.6 or later (if the minor version is 13.2 or later but earlier than 13.6, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)
    • Major version: 12; minor version: 12.10 or later (if the minor version is 12.6 or later but earlier than 12.10, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)
    • Major version: 11; minor version: 11.15 or later (if the minor version is 11.11 or later but earlier than 11.15, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)
    • Major version: 10; minor version: 10.20 or later (if the minor version is 10.16 or later but earlier than 10.20, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)
    • Major version: 9.6; minor version: 9.6.24 or later (if the minor version is 9.6.21 or later but earlier than 9.6.24, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)
    • Major version: 9.5; minor version: 9.6.25 or later (for some instances with the minor version of 9.5.25, SQL statements executed using psql can be collected, but those executed by other drivers like JDBC may not.)

Execution Duration Distribution of Top SQL Templates

  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 instance whose slow query logs you want to manage and click Details.
  7. Choose SQL > SQL Explorer.
  8. Toggle on Enable DAS SQL Explorer to obtain information about the executed SQL statements of the current instance.

    Figure 2 Toggling on DAS SQL explorer

    SQL Explorer takes effect once it is enabled.

  9. On the Top SQL tab page, view execution duration of top SQL statements.

    You can select Last 1 hour, Last 3 hours, or Last 6 hours based on service requirements to view the distribution. Or customize a time range that is no longer than one day.
    Figure 3 Execution durations of the top SQL templates

    The Execution Duration Distribution graph shows how many times SQL statements with different elapsed time lengths are executed over a specified time range. DAS collects SQL statistics of four elapsed time lengths.

    • < 100 ms: number of SQL statement executions whose elapsed time is less than 100 ms
    • 100 ms–500 ms: number of SQL statement executions whose elapsed time ranges from 100 ms to 500 ms
    • 500 ms–1s: number of SQL statement executions whose elapsed time ranges from 500 ms to 1s
    • > 1s: number of SQL statement executions whose elapsed time is longer than 1s

    SQL statistics in the four elapsed time lengths are collected over the time range you specified.

    • If you select Last hour, SQL statement executions are calculated every 10 seconds.
    • If you select Last 6 hours, SQL statement executions are calculated every minute.
    • If you select a time range longer than 6 hours, SQL statement executions are calculated every 5 minutes.
    Select By instance or By node to view execution duration distribution. You can change node to view its execution duration distribution. The primary node is selected by default. If you want to view the execution duration distribution of other nodes, click Change Node.
    Figure 4 Selecting another node

  10. Use either of the following methods to view execution duration details, such as average execution duration, total duration, average lock wait duration, and average scanned rows.

    • Hover your mouse at any point in time on the graph to view top SQL statements at that time.
      Figure 5 Viewing top SQL statements at a specific point in time
    • Specify a time range using your mouse on the graph, and you will see top SQL statements during that time range.
      Figure 6 Viewing top SQL statements in a specified time range
    • Click Export to export details about all top SQL templates in the list. This function is available only to paid instances.
    • In the SQL template list, locate a SQL template and click Details to view the total execution times, average rows scanned, average execution duration, and the like.
      Figure 7 Viewing details

SQL Audit

  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. On the Overview page, click Go to Intelligent O&M.
  5. Locate the instance whose slow query logs you want to manage and click Details.
  6. Choose SQL > SQL Explorer.
  7. Click the SQL Audit tab.

    Figure 8 SQL audit

  8. On the SQL Audit tab page, view all SQL audit tasks.

    • Specify the start time, end time, task creation time, and node information to search for SQL audit tasks.
      Figure 9 Querying SQL audit tasks
    • Click Add SQL Audit Task and specify a time range to add a task. You can add an instance- or node-level task based on your service requirements. The added SQL audit task is displayed in the list below.
      Figure 10 Adding a SQL audit task
    • Click View Details in the Operation column to view task details. You can specify filters such as Time Range, User, Keyword, or Database and click Query to search for the SQL statements executed on the current instance. The selected time range must be after the time when the SQL audit task is added.
      Figure 11 Details of the SQL audit task