Updated on 2024-04-03 GMT+08:00

Viewing Slow Query Logs

Slow query logs help you locate SQL statements that process a large amount of data, scan a large number of rows, or run for a long time, so that you can optimize them to improve database performance.

To use this function, you need to subscribe to Intelligent O&M first. For details, see Subscribing to Intelligent O&M.

If you did not subscribe to Intelligent O&M, you can view only the data of the last hour. The data will be automatically deleted when it expires.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
  4. On the Instances page, click the DB instance name.
  5. In the navigation pane, choose DBA Assistant > Historical Diagnosis.
  6. Click the Slow Query Log tab.
  7. In the Slow Queries over Time area, you can view the slow query log and vCPU usage trends of your DB instance.

    You can view the Slow Queries over Time chart in the last 1 hour, last 3 hours, last 12 hours, or a custom time period (spanning no more than one day).

    Figure 1 Slow Queries over Time

  8. Click Archive History and view slow query log data on the displayed page, including Log Started, Log Ended, and File Size(MB).

    Figure 2 Archived Slow Query Logs

    Slow query logs are automatically archived every three minutes. Alternatively, you can click Archive Now and then view the latest statistics.

  9. In Top 5 Slow Query Logs area, view the top 5 slow SQL statements sorted by user or client IP address.

    Figure 3 Top 5 Slow Query Logs

  10. In the details list, view details about slow query logs.

    • You can filter slow query logs by SQL statement, database, client IP address, user, execution duration, and scanned rows.
    • To export the slow query log list, click Export.
    • To view log export history, click View Export List.
    Figure 4 Details