You can call the DescribeSlowLogRecords operation to query the details of 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 ISO 8601 standard 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 ISO 8601 standard 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 returned entries.

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

The ID of the instance.

Engine String MySQL

The database engine that the instance runs.

PageNumber Integer 1

The page number of the returned page.

Items Array of SQLSlowRecord

An array that consists of the information about each slow query.

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 ISO 8601 standard in 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 response

XML format

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

<DescribeSlowLogRecordsResponse>
    <PageRecordCount>1</PageRecordCount>
    <RequestId>4DBB1BB0-E5D8-4D41-B1C9-142364DB****</RequestId>
    <TotalRecordCount>1</TotalRecordCount>
    <DBInstanceId>rm-uf6wjk5*******</DBInstanceId>
    <Engine>MySQL</Engine>
    <PageNumber>1</PageNumber>
    <Items>
        <HostAddress>xxx[xxx] @  [1xx.xxx.xxx.xx]</HostAddress>
        <RowsAffectedCount>34</RowsAffectedCount>
        <QueryTimes>2</QueryTimes>
        <SQLText>select sleep(2)</SQLText>
        <QueryTimeMS>2001</QueryTimeMS>
        <ApplicationName>example</ApplicationName>
        <LockTimes>0</LockTimes>
        <ExecutionStartTime>2020-06-18T01:40:44Z</ExecutionStartTime>
        <LogicalIORead>383</LogicalIORead>
        <WriteIOCount>22</WriteIOCount>
        <PhysicalIORead>200</PhysicalIORead>
        <ReturnRowCounts>1</ReturnRowCounts>
        <ParseRowCounts>1</ParseRowCounts>
        <DBName>testDB</DBName>
        <ClientHostName>example</ClientHostName>
        <UserName>user</UserName>
        <LastRowsAffectedCount>2</LastRowsAffectedCount>
        <SQLHash>U2FsdGVk****</SQLHash>
    </Items>
</DescribeSlowLogRecordsResponse>

JSON format

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

{
  "PageRecordCount" : 1,
  "RequestId" : "4DBB1BB0-E5D8-4D41-B1C9-142364DB****",
  "TotalRecordCount" : 1,
  "DBInstanceId" : "rm-uf6wjk5*******",
  "Engine" : "MySQL",
  "PageNumber" : 1,
  "Items" : [ {
    "HostAddress" : "xxx[xxx] @  [1xx.xxx.xxx.xx]",
    "RowsAffectedCount" : 34,
    "QueryTimes" : 2,
    "SQLText" : "select sleep(2)",
    "QueryTimeMS" : 2001,
    "ApplicationName" : "example",
    "LockTimes" : 0,
    "ExecutionStartTime" : "2020-06-18T01:40:44Z",
    "LogicalIORead" : 383,
    "WriteIOCount" : 22,
    "PhysicalIORead" : 200,
    "ReturnRowCounts" : 1,
    "ParseRowCounts" : 1,
    "DBName" : "testDB",
    "ClientHostName" : "example",
    "UserName" : "user",
    "LastRowsAffectedCount" : 2,
    "SQLHash" : "U2FsdGVk****"
  } ]
}

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 EndTime parameter.
400 IO.Exception IO exception, retry later. The error message returned because I/O errors occurred.

For a list of error codes, see Service error codes.