Updated on 2024-04-01 GMT+08:00

Querying Database Slow Logs

Description

This API is used to query database slow logs.

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

Restrictions

A maximum of 2000 records can be queried within the period specified by start_date and end_date.

URI

  • URI format

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

  • URI example
    • Query database slow query logs.

      https://dds.ap-southeast-1.myhuaweicloud.com/v3/0483b6b16e954cb88930a360d2c4e663/instances/6ade8143870047b8999aba8f1891b48ein02/slowlog?start_date=2018-08-06T10:41:14+0800&end_date=2018-08-07T10:41:14+0800

    • Query database slow query logs based on specified conditions.

      https://dds.ap-southeast-1.myhuaweicloud.com/v3/0549b4a43100d4f32f51c01c2fe4acdb/instances/6ade8143870047b8999aba8f1891b48ein02/slowlog?type=INSERT&offset=1&limit=20&node_id=a7c84462483642798cf159237343135fno06&start_date=2018-08-06T10:41:14+0800&end_date=2018-08-07T10:41:14+0800

Table 1 Parameter description

Name

Type

Mandatory

Description

X-Auth-Token

String

Yes

User token obtained from IAM. For details, see Authentication.

project_id

String

Yes

Project ID of a tenant in a region. To obtain the project ID, see Obtaining a Project ID.

instance_id

String

Yes

The instance ID, which can be obtained by calling the API for querying instances. If you do not have an instance, you can call the API used for creating an instance.

start_date

String

Yes

The 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.

CAUTION:

The start time is 31 days earlier than the current time.

end_date

String

Yes

The 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.

Only slow query logs generated within the last month can be queried.

NOTE:

The end time cannot be later than the current time.

node_id

String

No

The node ID. For details, see Table 8.

If this parameter is left blank, all nodes in the instance can be queried.

Nodes that can be queried:

Shard nodes in a cluster instance.

All nodes in a replica set or single node instance.

type

String

No

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

  • INSERT
  • QUERY
  • UPDATE
  • REMOVE
  • GETMORE
  • COMMAND
  • KILLCURSORS

offset

Integer

No

The index position. Its value range is [0, 1999].

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.

limit

Integer

No

The number of resources to be queried. The value ranges from 1 to 100. The default value is 10, indicating that 10 records are returned by default.

NOTE:

The sum of limit and offset values must be less than or equal to 2000.

Requests

None

Responses

  • Parameter description
    Table 2 Parameter description

    Name

    Type

    Description

    slow_log_list

    Array of objects

    The detailed information.

    For details, see Table 3.

    total_record

    Integer

    The total number of records.

    Table 3 slow_log_list field data structure description

    Name

    Type

    Description

    node_name

    String

    The node name.

    query_sample

    String

    The execution syntax.

    type

    String

    The statement type.

    time

    String

    The execution time.

    lock_time

    String

    The lock wait time.

    rows_sent

    String

    The number of sent rows.

    rows_examined

    String

    The number of scanned rows.

    database

    String

    The database which the slow log belongs to.

    start_time

    String

    The time in the UTC format.

  • Response example
    {
      "slow_log_list": [
        {
          "node_name": "Test_replica_node_2",
          "query_sample": "{\"responseLength\": 230, \"ts\": {\"$date\": 1605480486800}, \"ninserted\": 1, \"locks\": {\"oplog\": {\"acquireCount\": {\"w\": 1}}, \"Global\": {\"acquireCount\": {\"r\": 3, \"w\": 2}}, \"Collection\": {\"acquireCount\": {\"w\": 2}}, \"Database\": {\"acquireCount\": {\"w\": 3}}}, \"numYield\": 0, \"ns\": \"geographySpace.tiles\"}",
          "type": "REMOVE",
          "time": "101 ms",
          "lock_time": "10 us",
          "rows_sent": "0",
          "rows_examined": "0",
          "database": "geography",
          "start_time": "2020-11-15T22:49:38.643000Z"
        }
      ],
      "total_record": 1
    }

SDK

Click Document Database Service DDS SDK to download the SDK or view the SDK document. To learn how to install and authenticate an SDK, read the Usage section.

Status Code

For more information, see Status Code.

Error Code

For more information, see Error Code.