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

Querying Database Slow Logs (New)

API Description

This API is used to query slow logs by keyword or database table name.

Restrictions

  • Operators (such as &&, ||, AND, OR, NOT, *, ?, :, >, <, =, , and ) contained in raw logs cannot be used to search for logs.
  • A maximum of 100 records can be queried on each page.
  • Slow query logs can be stored for a maximum of 30 days.

URI

  • URI format

    POST https://{Endpoint}/v3.1/{project_id}/instances/{instance_id}/slow-logs

Table 1 Path parameters

Name

Type

IN

Mandatory

Description

project_id

string

path

Yes

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

instance_id

string

path

Yes

Instance ID, which can be obtained by calling the API described in Querying Instances and Details. If you do not have an instance, call the API described in Creating a DB Instance to create one.

Request Parameters

Table 2 Request header parameters

Parameter

Type

IN

Mandatory

Description

X-Auth-Token

string

header

Yes

User token

Table 3 Parameter description

Parameter

Type

Mandatory

Description

start_time

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.

CAUTION:

The start time cannot be 30 days earlier than the current time.

end_time

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.

NOTE:

The end time cannot be later than the current time.

limit

Integer

Yes

Number of logs to be queried each time. The maximum value is 100.

line_num

String

No

Sequence number of a log event. This parameter is not required for the first query, but is required for the next page query. The value can be obtained from the response of the last query.

NOTE:

The current query starts from the next log of line_num, excluding the log of line_num.

operate_type

String

No

Statement type. If this parameter is left empty, all statement types are queried.

Its value can be any of the following:

  • insert
  • query
  • update
  • remove
  • getmore
  • command
  • killcursors

search_type

String

No

Log query mode, which must be used together with line_num. The log of line_num is used as the start point.

  • If this parameter is set to backwards, logs of the limit size on the previous page are queried.
  • If this parameter is set to forwards, logs of the limit size on the next page are queried.
  • If this parameter is not specified, the default value forwards is used.

Enumerated values:

  • backwards
  • forwards

node_id

String

No

Node ID. For details, see Table 9.

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

keywords

Array of strings

No

Full-text log search based on multiple keywords, indicating that all keywords are matched.

  • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
  • Each keyword can contain a maximum of 512 characters.

database_keywords

Array of strings

No

Fuzzy search for logs based on multiple database keywords, indicating that at least one keyword is matched.

  • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
  • Each keyword can contain a maximum of 64 characters.

collection_keywords

Array of strings

No

Fuzzy search for logs based on multiple database table name keywords, indicating that at least one keyword is matched.

  • Only fuzzy search by keyword prefix is supported. A maximum of 10 keywords are supported.
  • Each keyword can contain a maximum of 128 characters.

max_cost_time

Integer

No

Logs can be searched based on the maximum execution duration.

Unit: ms

min_cost_time

Integer

No

Logs can be searched based on the minimum execution duration.

Unit: ms

max_docs_scanned

Integer

No

Logs can be searched based on the maximum scanned documents.

min_docs_scanned

Integer

No

Logs can be searched based on the minimum scanned documents.

max_docs_returned

Integer

No

Logs can be searched based on the maximum returned documents.

min_docs_returned

Integer

No

Logs can be searched based on the minimum returned documents.

min_keys_examined

Integer

No

Minimum number of scanned indexes.
  • The value must be zero or a positive integer.

max_keys_examined

Integer

No

Maximum number of scanned indexes.
  • The value must be zero or a positive integer and must be no less than the minimum number of scanned indexes.

username_keywords

Array of strings

No

Fuzzy search for logs based on multiple username keywords, indicating that at least one keyword is matched.
  • A maximum of 10 keywords are supported.
  • Each keyword can contain a maximum of 64 characters.

client_ip_keywords

Array of strings

No

Fuzzy search for logs based on multiple client IP address keywords, indicating that at least one keyword is matched.
  • A maximum of 10 keywords are supported.
  • Each keyword can contain a maximum of 15 characters.
  • Only keywords prefixed with IPv4 addresses are supported.
  • Example request
    { 
      "start_time" : "2022-09-06T10:41:14+0800", 
      "end_time" : "2022-09-16T10:41:14+0800", 
      "limit" : 100, 
      "line_num" : "1595659490239433658", 
      "operate_type" : "query", 
      "search_type":"forwards",
      "node_id" : "dbd0b65ed0c34125a0b04d4e5ba67e66no02", 
      "keywords" : [ "response", "oplog" ],
      "database_keywords" : [ "testDB" ], 
      "collection_keywords" : [ "testCollection" ], 
      "max_cost_time" : 100, 
      "min_cost_time" : 50,
      "max_docs_scanned" : 100,
      "min_docs_scanned" : 50,
      "max_docs_returned" : 100,
      "min_docs_returned" : 50,
      "min_keys_examined" : 10, 
      "max_keys_examined" : 100, 
      "username_keywords" : [ "user1", "user2" ], 
      "client_ip_keywords" : [ "211.", "172.12." ] 
    }

Response Parameters

Table 4 Parameter description

Parameter

Type

Description

slow_logs

Array of objects

Slow log information.

For details, see Table 5.

Table 5 Data structure description of field slowLogDetail

Parameter

Type

Description

node_name

String

Node name.

node_id

String

Node ID.

whole_message

String

Statement.

operate_type

String

Statement type.

cost_time

Integer

Execution time.

Unit: ms

lock_time

Integer

Lock wait time.

Unit: μs

docs_returned

Integer

Number of returned documents.

docs_scanned

Integer

Number of scanned documents.

database

String

Name of the database which the log belongs to.

collection

String

Name of the database table which the log belongs to.

log_time

String

UTC time when a log is generated. The format is yyyy-mm-ddThh:mm:ssZ. T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset.

line_num

String

Sequence number of a log event.

keys_examined

Integer

Number of scanned indexes.

username

String

Username.

client_ip

String

IP address of the client.

  • Example response
    { 
      "slow_logs" : [ { 
        "node_name" : "Test_replica_node_2", 
        "node_id" : "dbd0b65ed0c34125a0b04d4e5ba67e66no02", 
        "whole_message" : "{\"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\"}", 
        "operate_type" : "query", 
        "cost_time" : 60, 
        "lock_time" : 10, 
        "docs_returned" : 60, 
        "docs_scanned" : 70, 
        "database" : "testDB", 
        "collection" : "testCollection", 
        "log_time" : "2022-09-15T22:49:38.643000Z", 
        "line_num" : "1595659490239433659",
        "keys_examined" : 15, 
        "client_ip" : "172.89.10.11", 
        "username" : "user1" 
      } ] 
    }

Status Code

For details, see Status Code.

Error Code

For details, see Error Code.