Updated on 2024-05-21 GMT+08:00

Viewing Slow Query Logs

Scenarios

Slow query logs record statements that exceed long_query_time (10 seconds by default). You can view log details and statistics to identify statements that are executing slowly and optimize the statements.

GaussDB(for MySQL) supports the following statement types:
  • SELECT
  • INSERT
  • UPDATE
  • DELETE
  • CREATE
  • ALTER
  • DROP

Parameter Description

Table 1 Parameters related to slow queries

Parameter

Description

long_query_time

Specifies how many seconds a SQL query has to take to be recorded in slow query logs. The default value is 10s. You are advised to set this parameter to 1s.

The lock wait time is not calculated into the query time.

log_queries_not_using_indexes

Specifies whether to record the slow query that without indexes. The default value is OFF.

log_throttle_queries_not_using_indexes

Specifies the SQL statement that can be written to the slow query log every minute. The default value is 0.

Viewing Log Details

  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, choose Databases > GaussDB(for MySQL).
  4. On the Instances page, click the instance name to go to the Basic Information page.
  5. In the navigation pane on the left, choose Logs.
  6. On the Slow Query Logs page, view the slow query log details.

    You can download slow query logs.

  7. View slow query logs of different nodes in a given database and SQL statement types. In the upper right corner of the page:

    Enter a database name, click the drop-down list, and select your desired node.

    Click the drop-down list and select a SQL statement type (SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, or DROP).

    Click and specify a time period.

    Figure 1 Viewing slow query logs

Enabling Show Original Log

By default, SQL statements are displayed anonymously. If Show Original Log is enabled, SQL statements in the logs will be displayed in plaintext.

Logs displayed in plaintext will be automatically deleted 30 days later. If a DB instance is deleted, its related logs will also be deleted.

  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, choose Databases > GaussDB(for MySQL).
  4. On the Instances page, click the instance name to go to the Basic Information page.
  5. In the navigation pane on the left, choose Logs. On the Slow Query Logs tab, click next to Show Original Log.

    Figure 2 Enabling Show Original Log

  6. In the displayed dialog box, click Yes.

Reporting Slow Logs to LTS

  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, choose Databases > GaussDB(for MySQL).
  4. On the Instances page, click the instance name to go to the Basic Information page.
  5. In the navigation pane on the left, choose Logs.
  6. On the Slow Query Logs page, click next to Report Slow Log to LTS.
  7. Select an LTS log group and log stream and click OK.

    Figure 3 Reporting slow logs to LTS