Updated on 2024-09-11 GMT+08:00

Querying Database Slow Logs

Function

This API is used to query database slow logs. Before calling this API:

This API will be unavailable on March 31, 2025. You are advised to switch workloads to the new API (Querying Slow Query Logs) before then.

URI

  • URI format

    GET https://{endpoint}/mysql/v3/{project_id}/instances/{instance_id}/slowlog?offset={offset}&limit={limit}&level={level}&start_date={start_date}&end_date={end_date}&node_id={node_id}

  • Example

    GET https://{endpoint}/mysql/v3/97b026aa9cc4417888c14c84a1ad9860/instances/c3ec2c6148ad4d71b1a8411a62df0d3cin07/slowlog?offset=0&limit=100&level=ALL&start_date=2018-08-06T10:41:14+0800&end_date=2018-08-07T10:41:14+0800&node_id=cc07c60e94ec4575989840e648fb4f66no07

    • Parameter description
      Table 1 Parameter description

      Name

      Type

      Mandatory

      Description

      project_id

      String

      Yes

      Project ID of a tenant in a region.

      To obtain this value, see Obtaining a Project ID.

      instance_id

      String

      Yes

      DB instance ID.

      node_id

      String

      Yes

      Instance node ID.

      start_date

      String

      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

      String

      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.

      Only error logs generated within the last month can be queried.

      offset

      Integer

      No

      Index offset. If offset is set to N, the resource query starts from the N+1 piece of data. The default value is 0, indicating that the query starts from the first piece of data. The value must be a positive integer and the minimum value is 0.

      limit

      Integer

      No

      Number of records to be queried. The default value is 10. The value must be a positive integer. The minimum value is 1 and the maximum value is 100.

      type

      String

      No

      Statement type. The default value All. If this parameter is left empty, all statement types are queried. Values:

      • ALL
      • INSERT
      • UPDATE
      • SELECT
      • DELETE
      • CREATE
      • DROP
      • ALTER

    Request

    None.

Response

  • Normal response
    Table 2 Parameter description

    Name

    Type

    Description

    slow _log_list

    Array of objects

    Slow log information.

    For details, see Table 3.

    long_query_time

    String

    Threshold of slow logs in seconds.

    total_record

    Integer

    Total number of records.

    Table 3 error_log_list parameter description

    Name

    Type

    Description

    node_id

    String

    Node ID.

    time

    String

    Execution time.

    count

    String

    Number of executions.

    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.

    type

    String

    Statement type.

    start_time

    String

    Time in the UTC format.

    client_ip

    String

    IP address.

  • Example normal response

    {

    "slow_log_list":[

    {

    "node_id":"cc07c60e94ec4575989840e648fb4f66no07",

    "count":"1",

    "time":"1.04899 s",

    "lock_time":"0.00003 s",

    "rows_sent":"0",

    "rows_examined":"0",

    "database":"gaussdb-mysql",

    "users":"root",

    "query_sample":"INSERT INTO time_zone_name (Name, Time_zone_id) VALUES (N, @time_zone_id);",

    "type":"INSERT",

    "start_time":"2121-03-25T10:55:16",

    "client_ip ":"192.*.*.1"

    }

    ],

    "long_query_time":" 10",

    "total_record":15

    }

Status Code

For details, see Status Codes.

Error Code

For details, see Error Codes.