You can call the DescribeSlowLogRecords operation to query the slow query logs of an instance.

Note The response parameters returned by this operation are updated every minute.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes DescribeSlowLogRecords

The operation that you want to perform. Set the value to DescribeSlowLogRecords.

DBInstanceId String Yes rm-uf6wjk5******

The ID of the instance.

SQLHASH String No U2FsdGVk****

The unique ID of the SQL statement. The ID is used to obtain the slow query logs of the SQL statement.

StartTime String Yes 2020-06-17T16:00Z

The beginning of the time range to query. Specify the time in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

EndTime String Yes 2020-06-18T16:00Z

The end of the time range to query. The end time must be later than the start time. The time span between the start time and the end time must be less than 31 days. Specify the time in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

DBName String No RDS_MySQL

The name of the database.

PageSize Integer No 30

The number of entries to return on each page. Valid values: 30 to 100.

Note Default value: 30.
PageNumber Integer No 1

The number of the page to return. Valid values: any non-zero positive integer.

Note Default value: 1.

Response parameters

Parameter Type Example Description
PageRecordCount Integer 1

The number of SQL statements that are returned on the current page.

RequestId String 4DBB1BB0-E5D8-4D41-B1C9-142364DB****

The ID of the request.

TotalRecordCount Integer 1

The total number of entries returned.

DBInstanceId String rm-uf6wjk5*******

The ID of the instance.

Engine String MySQL

The database engine that the instance runs.

PageNumber Integer 1

The number of the returned page.

Items Array of SQLSlowRecord

An array that consists of slow query logs.

SQLSlowRecord
HostAddress String xxx[xxx] @ [1xx.xxx.xxx.xx]

The name and IP address of the client that is connected to the database.

RowsAffectedCount Long 34

The number of rows affected by the SQL statement.

Note This parameter is supported only by instances that run SQL Server.
QueryTimes Long 2

The execution duration of the slow query. Unit: seconds.

SQLText String select sleep(2)

The details of the SQL statement.

CpuTime Long 0.002

The duration during which the SQL statement is processed by the CPU. Unit: milliseconds.

Note This parameter is supported only by instances that run SQL Server.
QueryTimeMS Long 2001

The execution duration of the slow query. Unit: milliseconds.

ApplicationName String example

The name of the application that is connected to the instance.

Note This parameter is supported only by instances that run SQL Server.
LockTimes Long 0

The lock duration of the SQL statement. Unit: seconds.

ExecutionStartTime String 2020-06-18T01:40:44Z

The time when the execution of the SQL statement started. The time follows the yyyy-MM-ddTHH:mm:ssZ format. The time is displayed in UTC.

LogicalIORead Long 383

The number of logical reads.

Note This parameter is supported only by instances that run SQL Server.
WriteIOCount Long 22

The number of I/O writes.

Note This parameter is supported only by instances that run SQL Server.
PhysicalIORead Long 200

The number of physical reads.

Note This parameter is supported only by instances that run SQL Server.
ReturnRowCounts Long 1

The number of rows returned by the SQL statement.

ParseRowCounts Long 1

The number of rows parsed by the SQL statement.

DBName String testDB

The name of the database.

ClientHostName String example

The hostname of the client.

Note This parameter is supported only by instances that run SQL Server.
UserName String user

The username of the account that is used to connect to the instance.

Note This parameter is supported only by instances that run SQL Server.
LastRowsAffectedCount Long 2

The number of rows that are affected by the last SQL statement.

Note This parameter is supported only by instances that run SQL Server.
SQLHash String U2FsdGVk****

The unique ID of the SQL statement.

Examples

Sample requests

http(s)://rds.aliyuncs.com/?Action=DescribeSlowLogRecords
&DBInstanceId=rm-uf6wjk5*******
&StartTime=2020-06-17T16:00Z
&EndTime=2020-06-18T16:00Z
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<DescribeSlowLogRecordsResponse>
    <TotalRecordCount>1</TotalRecordCount>
    <PageRecordCount>1</PageRecordCount>
    <RequestId>4DBB1BB0-E5D8-4D41-B1C9-142364DB****</RequestId>
    <DBInstanceId>rm-uf6wjk5*******</DBInstanceId>
    <PageNumber>1</PageNumber>
    <Items>
        <SQLSlowRecord>
            <QueryTimes>2</QueryTimes>
            <ExecutionStartTime>2020-07-20T02:03:10Z</ExecutionStartTime>
            <ReturnRowCounts>1</ReturnRowCounts>
            <LockTimes>0</LockTimes>
            <DBName>testDB</DBName>
            <ParseRowCounts>1</ParseRowCounts>
            <HostAddress>test1[test1] @  [100.xxx.xxx.xxx]</HostAddress>
            <QueryTimeMS>2000</QueryTimeMS>
            <SQLText>select sleep(2)</SQLText>
        </SQLSlowRecord>
    </Items>
    <Engine>MySQL</Engine>
</DescribeSlowLogRecordsResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "TotalRecordCount" : 1,
  "PageRecordCount" : 1,
  "RequestId" : "4DBB1BB0-E5D8-4D41-B1C9-142364DB****",
  "DBInstanceId" : "rm-uf6wjk5*******",
  "PageNumber" : 1,
  "Items" : {
    "SQLSlowRecord" : [ {
      "QueryTimes" : 2,
      "ExecutionStartTime" : "2020-07-20T02:03:10Z",
      "ReturnRowCounts" : 1,
      "LockTimes" : 0,
      "DBName" : "testDB",
      "ParseRowCounts" : 1,
      "HostAddress" : "test1[test1] @  [100.xxx.xxx.xxx]",
      "QueryTimeMS" : 2000,
      "SQLText" : "select sleep(2)"
    } ]
  },
  "Engine" : "MySQL"
}

Error codes

HTTP status code Error code Error message Description
400 InvalidSearchTimeRange search time range cannot be longer than a month. The error message returned because the time span between the start time and the end time exceeds 31 days. Enter a valid value for the StartTime or the EndTime parameter.
400 IO.Exception IO exception, retry later. The error message returned because I/O errors occurred.

For a list of error codes, visit the API Error Center.