Updated on 2025-06-25 GMT+08:00

Exporting Slow Query Logs

Function

  • After Collect Slow Query Logs is enabled, you can export the slow query logs within a specified period all at once. The data can be obtained by page.
  • For free instances, you can only view data generated in the last hour.

URI

GET /v3/{project_id}/instances/{instance_id}/slow-query-logs

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Explanation:

Project ID of a tenant in a region

To obtain this value, see Obtaining a Project ID.

Constraints:

N/A

Values:

The value can contain 32 characters. Only letters and digits are allowed.

Default value:

N/A

instance_id

Yes

String

Explanation:

Unique ID of an instance

Constraints:

N/A

Values:

The value can contain 32 characters. Only letters and digits are allowed.

Default value:

N/A

Table 2 Query parameters

Parameter

Mandatory

Type

Description

datastore_type

Yes

String

Explanation:

Database type

Constraints:

N/A

Values:

  • MySQL
  • TaurusDB
  • PostgreSQL

Default value:

N/A

start_at

Yes

Long

Explanation:

Start time

Constraints:

Unix timestamp, in milliseconds

Values:

[0, 2^31-1]. The actual value depends on the query result.

Default value:

N/A

end_at

Yes

Long

Explanation:

End time

Constraints:

Unix timestamp, in milliseconds

Values:

[0, 2^31-1]. The actual value depends on the query result.

Default value:

N/A

limit

Yes

Integer

Explanation:

Records on each page

Constraints:

N/A

Values:

[0, 2000]. The actual value depends on the query result.

Default value:

N/A

marker

No

String

Explanation:

Query result marker. When the first page is obtained, no value needs to be assigned to this parameter. When the next page is obtained, the returned value of the first page query result is used.

Constraints:

N/A

Values:

N/A

Default value:

N/A

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

slow_logs

Array of slow log objects

Explanation:

Slow query logs. If the set is empty, all slow query logs have been exported.

Values:

N/A

next_marker

String

Explanation:

Marker required for obtaining the next page. This parameter is valid only within 3 minutes.

Values:

N/A

Table 4 SlowLog

Parameter

Type

Description

sql

String

Explanation:

SQL statement

Values:

N/A

sql_template_id

String

Explanation:

SQL template ID

Values:

N/A

database

String

Explanation:

Database name

Values:

N/A

client

String

Explanation:

Client

Values:

N/A

user

String

Explanation:

User

Values:

N/A

execute_at

Long

Explanation:

Execution start time in the Unix timestamp format, in milliseconds

Values:

[0, 2^31-1]. The actual value depends on the query result.

query_time

Double

Explanation:

Duration (s)

Values:

N/A

lock_time

Double

Explanation:

Lock wait time (s)

Values:

N/A

rows_examined

Long

Explanation:

Number of scanned rows

Values:

[0, 2^31-1]. The actual value depends on the query result.

rows_sent

Long

Explanation:

Returned rows

Values:

[0, 2^31-1]. The actual value depends on the query result.

Example Request

Exporting slow query logs

GET https://das.cn-north-1.myhuaweicloud.com/v3/054e292c9880d4992f02c0196d3ea468/instances/da304cd5bbb944de828759bc7be3d3fein01/slow-query-logs?start_at=1611975464337&end_at=1611979064337&limit=10&marker=DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAQH8YWSEFfM3FyOXZRNzJQOTVLNHNBOTQ2UQ==&datastore_type=MySQL

Example Response

Status code: 200

Response body for exporting slow query logs

{
  "slow_logs" : [ {
    "execute_at" : 1612343898000,
    "sql" : "SELECT sleep(10)\nLIMIT 0, 50;",
    "sql_template_id" : "AAD913807ECE9C66",
    "database" : "123",
    "client" : "[100.79.0.248]",
    "user" : "root[root]",
    "query_time" : 10.000158309936523,
    "lock_time" : 0,
    "rows_examined" : 0,
    "rows_sent" : 1
  } ],
  "next_marker" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAJr48WZERxYkx5Q2VRQS1LSXRrRWt0VEN1QQ=="
}

Status Codes

Status Code

Description

200

Successful request

400

Client error

500

Server error

Error Codes

See Error Codes.