Updated on 2023-10-18 GMT+08:00

Querying Database Slow Logs

Function

This API is used to query database slow logs. Before calling this API:

URI

GET /v3/{project_id}/instances/{instance_id}/slowlog

Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID of a tenant in a region.

To obtain this value, see Obtaining a Project ID.

instance_id

Yes

String

Instance ID.

Table 2 Query parameters

Parameter

Mandatory

Type

Description

start_date

Yes

String

Start time in the "yyyy-mm-ddThh:mm:ssZ" format.

end_date

Yes

String

End time in the "yyyy-mm-ddThh:mm:ssZ" format.

Only error logs generated within the last month can be queried.

offset

No

Integer

Index offset. If offset is set to N, the resource query starts from the N+1 piece of data. The value is 0 by default, indicating that the query starts from the first piece of data. The value cannot be a negative number.

limit

No

Integer

Number of records to be queried. The default value is 100. The value must be a positive integer. The minimum value is 1 and the maximum value is 100.

type

No

String

Statement type. The default value All. If this parameter is left empty, all statement types are queried. Valid value:

  • ALL
  • INSERT
  • UPDATE
  • SELECT
  • DELETE
  • CREATE
  • DROP
  • ALTER

node_id

Yes

String

Node ID.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

If the following response body is returned for calling the API used to obtain a user token, the request is successful.

After the request is processed, the value of X-Subject-Token in the message header is the token value.

X-Language

No

String

Request language type. The default value is en-us.

Value:

  • en-us
  • zh-cn

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

slow_log_list

Array of MysqlSlowLogList objects

Error log details.

long_query_time

String

Slow query log threshold.

total_record

Integer

Total number of records.

Table 5 MysqlSlowLogList

Parameter

Type

Description

node_id

String

Node ID.

count

String

Number of executions.

time

String

Execution time.

lock_time

String

Lock wait time.

rows_sent

String

Number of sent rows.

rows_examined

String

Number of scanned rows.

database

String

Database which slow logs belong to.

users

String

Account.

query_sample

String

Execution syntax.

type

String

Statement type.

start_time

String

Start time in the UTC format.

client_ip

String

IP address.

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 logs whose statement type is INSERT

GET https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances/096c0fc43e804757b59946b80dc27f8bin07/slowlog?offset=0&limit=1&start_date=2022-07-10T00:00:00+0800&end_date=2022-07-19T00:00:00+0800&node_id=cc07c60e94ec4575989840e648fb4f66no07&type=INSERT

Example Response

Status code: 200

Success.

{
  "slow_log_list" : [ {
    "node_id" : "cc07c60e94ec4575989840e648fb4f66no07",
    "count" : 1,
    "time" : "1.04899 s",
    "lock_time" : "0.00003 s",
    "rows_sent" : 0,
    "rows_examined" : 0,
    "database" : "gaussdb-mysql",
    "users" : "root",
    "query_sample" : "INSERT INTO time_zone_name (Name, Time_zone_id) VALUES (N @time_zone_id);",
    "type" : "INSERT",
    "start_time" : "2121-03-25T10:55:16.000Z",
    "client_ip" : "192.*.*.1"
  } ],
  "long_query_time" : 10,
  "total_record" : 15
}

Status Code

For details, see Status Codes.

Error Code

For details, see Error Codes.