Updated on 2024-06-07 GMT+08:00

Querying Database Slow Logs (MySQL)

Function

This API is used to query the latest slow logs of a DB instance. A maximum of 2,000 log records can be queried.

  • Before calling an API, you need to understand the API in Authentication.

Constraints

This API is supported only for MySQL.

URI

  • URI format

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

  • Parameter description
    Table 1 Parameter description

    Name

    Mandatory

    Description

    project_id

    Yes

    Project ID of a tenant in a region.

    For details about how to obtain the project ID, see Obtaining a Project ID.

    instance_id

    Yes

    ID of the instance to be queried.

    start_date

    Yes

    Start time 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.

    end_date

    Yes

    End time 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. You can only query slow logs generated within a month.

    offset

    No

    Index offset.

    If offset is set to N, the resource query starts from the N+1 piece of data. The value is 0 by default, indicating that the query starts from the first piece of data. The value cannot be a negative number.

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

    limit

    No

    Number of records (query results) displayed on each page. The number ranges from 1 to 100. The default value is 10.

    type

    No

    Statement type. If it is left blank, all statement types are queried. Valid value:

    • INSERT
    • UPDATE
    • SELECT
    • DELETE
    • CREATE

Request

  • Request parameters

    None

Response

  • Normal response
    Table 2 Parameter description

    Name

    Type

    Description

    slow_log_list

    Array of objects

    Detailed information.

    For details, see Table 3.

    total_record

    Integer

    Total number of records.

    Table 3 slow_log_list field data structure description

    Name

    Type

    Description

    count

    String

    Number of executions.

    time

    String

    Execution time.

    lock_time

    String

    Lock wait time.

    rows_sent

    String

    Number of sent rows.

    rows_examined

    String

    Number of scanned rows.

    database

    String

    Database which slow logs belong to.

    users

    String

    Account.

    query_sample

    String

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

    type

    String

    Statement type.

    start_time

    String

    Start time in the UTC format.

    client_ip

    String

    IP address.

  • 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 Request Results.

Status Code

Error Code

For details, see Error Codes.