Updated on 2026-08-25 GMT+08:00

(Recommended) Querying Slow Query Logs

Function

This API is used to query the latest 2,000 slow query logs of a DB instance.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
  • If you are using role/policy-based authorization, see Permissions and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

rds:log:getSlowLogs

read

-

-

rds:log:list

-

Constraints

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

URI

  • URI format

    GET /v3/{project_id}/instances/{instance_id}/slowlog?start_date={start_date}&end_date={end_date}

  • 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

    Instance ID.

    You can obtain the value of this parameter from id in Table 4 by calling the API for querying DB instances.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

    start_date

    Yes

    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_date

    Yes

    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

    offset

    No

    Definition

    Page offset.

    Constraints

    The latest 2,000 slow query logs can be queried. The value of offset multiplied by the value of limit must be no more than 2,000. For example, if the value of offset is set to 200, and the value of limit cannot be greater than 10.

    Range

    For example, 1, 2, 3, or 4

    Default Value

    If this parameter is not specified, the default value 1 is used, indicating that data on the first page is queried.

    limit

    No

    Definition

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

    Constraints

    N/A

    Range

    An integer ranging from 1 to 100

    Default Value

    10

    type

    No

    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

Request

  • Request parameters

    None

  • URI example

    GET https://{endpoint}/v3/0483b6b16e954cb88930a360d2c4e663/instances/cee5265e1e5845649e354841234567dfin01/slowlog?offset=1&limit=10&start_date=2018-08-06T10:41:14+0800&end_date=2018-08-07T10:41:14+0800&type=INSERT

Response

  • Normal response
    Table 2 Parameters

    Parameter

    Type

    Description

    slow_log_list

    Array of objects

    Definition

    Detailed information.

    For details, see Table 3.

    total_record

    Integer

    Definition

    Total number of records.

    Range

    N/A

    Table 3 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 query 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

    • INSERT
    • UPDATE
    • SELECT
    • DELETE
    • CREATE

    start_time

    String

    Definition

    Start time in the UTC format.

    Range

    N/A

    client_ip

    String

    Definition

    IP address.

    Range

    N/A

  • Example normal response
    {
        "total_record": 1,
        "slow_log_list": [
            {
                "count": "1",
                "time": "1.04899 s",
                "lock_time": "0.00003 s",
                "rows_sent": "0",
                "rows_examined": "0",
                "database": "mysql",
                "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"
            }
        ]
    }
  • Abnormal Response

    For details, see Abnormal Response Results.

Status Code

Error Code

For details, see Error Codes.