Updated on 2026-01-20 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.

Authorization Information

Each account has permissions to call all APIs, but IAM users must have the required permissions specifically assigned.

  • If you are using role/policy-based authorization, see the required permissions in Permissions Policies and Supported Actions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    das:clouddba:slowSqlExport

    list

    Instance

    -

    -

    -

URI

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

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 can contain 32 characters. Only letters and digits are allowed.

Default Value

N/A

instance_id

Yes

String

Definition

Unique ID of an instance

Constraints

N/A

Range

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

Definition

Database type

Constraints

N/A

Range

  • MySQL
  • TaurusDB
  • PostgreSQL

Default Value

N/A

start_at

Yes

Long

Definition

Start time

Constraints

Unix timestamp, in milliseconds

Range

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

Default Value

N/A

end_at

Yes

Long

Definition

End time

Constraints

Unix timestamp, in milliseconds

Range

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

Default Value

N/A

limit

Yes

Integer

Definition

Records on each page

Constraints

N/A

Range

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

Default Value

N/A

marker

No

String

Definition

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

Range

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

Definition

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

Range

N/A

next_marker

String

Definition

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

Range

N/A

Table 4 SlowLog

Parameter

Type

Description

sql

String

Definition

SQL statement

Range

N/A

sql_template_id

String

Definition

SQL template ID

Range

N/A

database

String

Definition

Database name

Range

N/A

client

String

Definition

Client

Range

N/A

user

String

Definition

User

Range

N/A

execute_at

Long

Definition

Execution start time in the Unix timestamp format, in milliseconds

Range

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

query_time

Double

Definition

Duration (s)

Range

N/A

lock_time

Double

Definition

Lock wait time (s)

Range

N/A

rows_examined

Long

Definition

Number of scanned rows

Range

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

rows_sent

Long

Definition

Returned rows

Range

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

Example Requests

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 Responses

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 response

400

Client error

500

Server error

Error Codes

See Error Codes.