Help Center/ TaurusDB/ API Reference/ APIs (Recommended)/ Log Management/ Querying Slow Query Log Statistics
Updated on 2025-09-04 GMT+08:00

Querying Slow Query Log Statistics

Function

This API is used to query slow query log statistics. Before calling this API:

URI

POST /v3/{project_id}/instances/{instance_id}/slow-logs/statistics

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID of a tenant in a region.

To obtain this value, see Obtaining a Project ID.

Constraints

N/A

Range

The value contains 32 characters. Only letters and digits are allowed.

Default Value

N/A

instance_id

Yes

String

Definition

Instance ID, which uniquely identifies an instance.

Constraints

N/A

Range

The value contains 36 characters with a suffix of in07. Only letters and digits are allowed.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. To obtain this value, call the IAM API for obtaining a user token.

The value of X-Subject-Token in the response header is the token value.

Constraints

N/A

Range

N/A

Default Value

N/A

X-Language

No

String

Definition

Request language type.

Constraints

N/A

Range

  • en-us

  • zh-cn

Default Value

en-us

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

limit

No

Integer

Definition

Number of records to be queried.

Constraints

The value cannot be a negative number.

Range

1–100

Default Value

100

offset

No

Integer

Definition

Index offset. The query starts from the next piece of data indexed by this parameter.

Constraints

The value cannot be a negative number.

Range

≥ 0

Default Value

0

node_id

Yes

String

Definition

Node ID.

Constraints

N/A

Range

The value contains 36 characters, starting with a UUID and ending with no07. Only letters and digits are allowed.

Default Value

N/A

type

No

String

Definition

Statement. If this parameter is left empty, all statements are queried.

Constraints

N/A

Range

  • INSERT

  • UPDATE

  • SELECT

  • DELETE

  • CREATE

  • ALL

Default Value

N/A

database

No

String

Definition

Database name.

Constraints

It cannot contain special characters such as < > &.

Range

N/A

Default Value

N/A

start_time

Yes

String

Definition

Start time. 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. For example, in the Beijing time zone, the offset is +0800.

Constraints

N/A

Range

N/A

Default Value

N/A

end_time

Yes

String

Definition

End time. 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. For example, in the Beijing time zone, the offset is +0800. Only slow query logs generated within the past month can be queried.

Constraints

N/A

Range

N/A

Default Value

N/A

sort

No

String

Definition

Sorting field.

Constraints

N/A

Range

  • If this parameter is set to executeTime, slow query logs are sorted by average execution duration in descending order.

  • If this parameter is left empty or set to other values, the slow query logs are sorted by executions in descending order.

Default Value

N/A

order

No

String

Definition

Sorting sequence.

Constraints

N/A

Range

  • desc: The query results are displayed in the descending order.

  • asc: The query results are displayed in ascending order.

Default Value

desc

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

slow_log_list

Array of ShowSlowLogStatisticsItem objects

Definition

List of slow query log statistics.

total_count

Integer

Definition

Total records.

Range

N/A

Table 5 ShowSlowLogStatisticsItem

Parameter

Type

Description

client_ip

String

Definition

IP address.

Default Value

N/A

count

String

Definition

Number of executions.

Default Value

N/A

database

String

Definition

Database that slow query logs belong to.

Default Value

N/A

lock_time

String

Definition

Average lock wait time.

Default Value

N/A

node_id

String

Definition

Node ID.

Default Value

Same as the input parameter

query_sample

String

Definition

Execution syntax.

Default Value

N/A

rows_examined

Integer

Definition

Average number of scanned rows.

Default Value

N/A

rows_sent

Integer

Definition

Average number of rows contained in a result.

Default Value

N/A

time

String

Definition

Average execution duration.

Default Value

N/A

type

String

Definition

Statement type.

Default Value

N/A

users

String

Definition

Account.

Default Value

N/A

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Request

Querying slow query log statistics

POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances/6754902da1f447269c6979b0590102a5in07/slow-logs/statistics

{
  "limit" : 10,
  "offset" : 0,
  "node_id" : "4006312b96c541749d735c20e86dd169no07",
  "type" : null,
  "database" : null,
  "start_time" : "2024-08-16T14:37:00+0800",
  "end_time" : "2024-08-16T16:51:22+0800",
  "sort" : null,
  "order" : "desc"
}

Example Response

Status code: 200

Success.

{
  "slow_log_list" : [ {
    "node_id" : "4006312b96c541749d735c20e86dd169no07",
    "count" : "1 (100.00%)",
    "time" : "11.00014 s",
    "lock_time" : "0.00000 s",
    "rows_sent" : 1,
    "rows_examined" : 1,
    "database" : "",
    "users" : "root",
    "query_sample" : "select sleep(N);",
    "client_ip" : "localhost",
    "type" : "SELECT"
  } ],
  "total_count" : 1
}

Status Code

For details, see Status Codes.

Error Code

For details, see Error Codes.