Updated on 2025-09-05 GMT+08:00

Querying Slow Query Logs Through LTS

Function

This API is used to query slow query logs of a DB instance when Log Tank Service (LTS) is available in the current region.

Constraints

This API is available only to RDS for MySQL and RDS for PostgreSQL.

In RDS for MySQL slow query logs, if the length of a single line of an SQL statement exceeds 10 KB or the total number of lines exceeds 200, the SQL statement will be truncated. When you view slow query log details, the SQL statement may be incomplete after special processing and is for reference only.

URI

  • URI format

    POST /v3/{project_id}/instances/{instance_id}/slow-logs

  • Parameter description
    Table 1 Parameters

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Definition

    Project ID of a tenant in a region.

    To obtain the value, see Obtaining a Project ID.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

    instance_id

    Yes

    Definition

    ID of the instance to be queried.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

Request

Table 2 Parameters

Parameter

Mandatory

Type

Description

start_time

Yes

String

Definition

Start time.

Constraints

N/A

Range

The value is in the "yyyy-mm-ddThh:mm:ssZ" format.

T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset. For example, in the Beijing time zone, the time zone offset is shown as +0800. The start time cannot be more than one month earlier than the current time.

Default Value

N/A

end_time

Yes

String

Definition

End time.

Constraints

N/A

Range

The value is in the "yyyy-mm-ddThh:mm:ssZ" format.

T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset. For example, in the Beijing time zone, the time zone offset is shown as +0800. Only slow query logs generated within the past month can be queried.

Default Value

N/A

type

No

String

Definition

Statement type.

Constraints

N/A

Range

If this parameter is left blank, all statement types are queried.

Enumerated values:

  • INSERT
  • UPDATE
  • SELECT
  • DELETE
  • CREATE

Default Value

N/A

line_num

No

String

Definition

Sequence number of a log event.

Constraints

This parameter is not required for the first query, but is required for subsequent pagination queries. The value can be obtained from the response of the last query.

Range

The value of line_num should be between the values of start_time and end_time.

Default Value

N/A

limit

No

Integer

Definition

Number of records (query results) displayed on each page.

Constraints

N/A

Range

1–100

Default Value

If this parameter is not specified, the default value 10 is used.

search_type

No

String

Definition

Search mode. This parameter is used together with line_num.

Constraints

N/A

Range

  • forwards: Search forwards starting from line_num.
  • backwards: Search backwards starting from line_num.

Default Value

forwards

database

No

String

Definition

Database name.

Constraints

It cannot contain special characters such as < > &.

Range

N/A

Default Value

N/A

Example Request

Query slow query logs. Each page contains 10 records.
POST https://{endpoint}/v3/0483b6b16e954cb88930a360d2c4e663/instances/cee5265e1e5845649e354841234567dfin01/slow-logs

{
    "start_time":"2023-01-02T23:58:57+0000",
    "end_time":"2023-01-06T01:47:20+0000",
    "limit":10,
    "line_num":"1672908793000000000"
}

Response

  • Normal response
    Table 3 Parameters

    Parameter

    Type

    Description

    slow_log_list

    Array of objects

    Definition

    Slow query logs.

    For details, see Table 4.

    long_query_time

    String

    Definition

    Threshold for slow query logs.

    Range

    N/A

    Table 4 slow_log_list field data structure description

    Parameter

    Type

    Description

    count

    String

    Definition

    Number of executions.

    Range

    N/A

    time

    String

    Definition

    Execution time.

    Range

    N/A

    lock_time

    String

    Definition

    Lock wait time. Only RDS for MySQL supports this parameter.

    Range

    N/A

    rows_sent

    String

    Definition

    Number of sent rows. Only RDS for MySQL supports this parameter.

    Range

    N/A

    rows_examined

    String

    Definition

    Number of scanned rows. Only RDS for MySQL supports this parameter.

    Range

    N/A

    database

    String

    Definition

    Database which slow logs belong to. If any database name contains special characters such as < > ', the special characters will be escaped.

    Range

    N/A

    users

    String

    Definition

    Account.

    Range

    N/A

    query_sample

    String

    Definition

    Execution syntax. By default, slow query logs are anonymized. To display them in plaintext, contact customer service.

    Range

    N/A

    type

    String

    Definition

    Statement type.

    Range

    N/A

    start_time

    String

    Definition

    Start time in the UTC format.

    Range

    N/A

    client_ip

    String

    Definition

    IP address.

    Range

    N/A

    line_num

    String

    Definition

    Sequence number of a log event.

    Range

    N/A

  • Example normal response
    {
      "slow_log_list" : [ { 
        "count" : "1", 
        "time" : "1.04899 s", 
        "lock_time" : "0.00003 s", 
        "rows_sent" : "0", 
        "rows_examined" : "0", 
        "database" : "test_db", 
        "users" : "root", 
        "query_sample" : "INSERT INTO time_zone_name (Name, Time_zone_id) VALUES (N, @time_zone_id);", 
        "type" : "INSERT", 
        "start_time" : "2018-08-06T10:41:14", 
        "client_ip" : "192.*.*.1", 
        "line_num" : "1595659490239433658" 
      } ], 
      "long_query_time" : "1" 
    }
  • Abnormal response

    For details, see Abnormal Request Results.

Status Code

Error Code

For details, see Error Codes.