Updated on 2025-05-19 GMT+08:00

Exporting All Query Logs

Function

After Collect All Query Logs is enabled, you can export all query logs within a specified period. The data can be obtained by page. This function is available only for paid instances.

URI

GET /v3/{project_id}/instances/{instance_id}/sql-statements

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

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

datastore_type

Yes

String

Explanation:

Database type

Constraints:

N/A

Values:

  • MySQL
  • TaurusDB

Default value:

N/A

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

statements

Array of FullSql objects

Explanation:

All query logs. If the set is empty, all 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 FullSql

Parameter

Type

Description

sql

String

Explanation:

SQL statement

Values:

N/A

operate_type

String

Explanation:

Operation type

Values:

N/A

status

String

Explanation:

Status

Values:

N/A

error_no

String

Explanation:

Error code

Values:

N/A

database

String

Explanation:

Database name

Values:

N/A

client

String

Explanation:

Client

Values:

N/A

thread_id

String

Explanation:

Thread ID

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:

Execution duration, in milliseconds

Values:

N/A

lock_time

Double

Explanation:

Lock wait time (ms)

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.

rows_affected

Long

Explanation:

Updated rows

Values:

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

Example Request

Exporting all query logs

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

Example Response

Status code: 200

Response body for exporting all query logs

{
  "statements" : [ {
    "sql" : "SELECT 1",
    "operate_type" : "select",
    "status" : "success",
    "error_no" : "",
    "database" : "",
    "thread_id" : "11481954",
    "client" : "100.79.3.154",
    "user" : "root",
    "execute_at" : 1612403000100,
    "query_time" : 0,
    "lock_time" : 0,
    "rows_examined" : 0,
    "rows_sent" : 1,
    "rows_affected" : 0
  } ],
  "next_marker" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAASG3cWcHVpdktBU1lTbjJMM2tmYXYxZ09nUQ=="
}

Status Codes

Status Code

Description

200

Response body for exporting all SQL statements.

400

Client error.

500

Server error.

Error Codes

See Error Codes.