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

Before you call this operation, make sure that the instance runs one of the following database engine versions:

  • All MySQL versions other than MySQL 5.7 on RDS Basic Edition
  • SQL Server 2008 R2
  • MariaDB 10.3
Note Slow query logs are not collected in real time and may show a latency of 6 hours to 8 hours.

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

ParameterTypeRequiredExampleDescription
ActionStringYesDescribeSlowLogs

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

DBInstanceIdStringYesrm-uf6wjk5xxxxxxx

The ID of the instance.

StartTimeStringYes2011-05-01Z

The beginning of the time range to query. Specify the time in the ISO 8601 standard in the yyyy-MM-ddZ format. The time must be in UTC.

EndTimeStringYes2011-05-30Z

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 cannot exceed 31 days. Specify the time in the ISO 8601 standard in the yyyy-MM-ddZ format. The time must be in UTC.

DBNameStringNoRDS_MySQL

The name of the database.

SortKeyStringNoTotalExecutionCounts

The dimension based on which ApsaraDB RDS sorts the entries to return. Valid values:

  • TotalExecutionCounts: ApsaraDB RDS sorts the entries to return based on the number of times that SQL statements are executed.
  • TotalQueryTimes: ApsaraDB RDS sorts the entries to return based on the total execution duration.
  • TotalLogicalReads: ApsaraDB RDS sorts the entries to return based on the total number of logical reads.
  • TotalPhysicalReads: ApsaraDB RDS sorts the entries to return based on the total number of physical reads.
Note This parameter is supported only for instances that run SQL Server 2008 R2.
PageSizeIntegerNo30

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

PageNumberIntegerNo1

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

Default value: 1.

Response parameters

ParameterTypeExampleDescription
EndTimeString2011-05-30Z

The end date of the time range that was queried.

StartTimeString2011-05-30Z

The start date of the time range that was queried.

RequestIdString2553A660-E4EB-4AF4-A402-8AFF70A49143

The ID of the request.

PageRecordCountInteger10

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

TotalRecordCountInteger5

The total number of returned entries.

DBInstanceIdStringrm-uf6wjk5xxxxxxx

The ID of the instance.

PageNumberInteger1

The page number of the returned page.

EngineStringMySQL

The database engine that the instance runs.

ItemsArray of SQLSlowLog

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

SQLSlowLog
MaxLastRowsAffectedCountsLong0

The largest number of rows that were affected by the last SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
ReturnMaxRowCountLong1

The largest number of rows that were returned by a specific SQL statement in the query.

SQLTextStringselect id,name from tb_table

The SQL statement that was executed in the query.

SQLServerMaxCpuTimeLong0

The largest amount of CPU time that was used by a specific SQL statement in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
CreateTimeString2011-05-30Z

The date when the data was generated.

AvgLastRowsAffectedCountsLong0

The average number of rows that were affected by the last SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
MinLastRowsAffectedCountsLong0

The smallest number of rows that were affected by the last SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
ParseTotalRowCountsLong1

The total number of rows that were parsed by all SQL statements in the query.

TotalLockTimesLong0

The total lock duration that was caused by all SQL statements in the query. Unit: seconds.

MySQLTotalExecutionCountsLong1

The total number of SQL statements that were executed in the query. This parameter is returned only for instances that run MySQL.

SQLServerMinCpuTimeLong0

The smallest amount of CPU time that was used by a specific SQL statement. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
SQLHASHStringU2FsdGVkxxxx

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

MinIOWriteCountsLong0

The smallest number of I/O writes that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
ParseMaxRowCountLong1

The largest number of rows that were parsed by a specific SQL statement in the query.

MaxLogicalReadCountsLong0

The largest number of logical reads that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
MySQLTotalExecutionTimesLong1

The total execution duration of all SQL statements in the query. This parameter is returned only for instances that run MySQL. Unit: seconds.

SQLServerTotalExecutionCountsLong1

The total number of SQL statements that were executed in the query. This parameter is returned only for instances that run SQL Server.

ReturnTotalRowCountsLong1

The total number of rows that were returned by all SQL statements in the query.

MaxLockTimeLong0

The longest lock duration that was caused by a specific SQL statement in the query. Unit: seconds.

DBNameStringRDS_MySQL

The name of the database.

MinRowsAffectedCountsLong0

The smallest number of rows that were affected by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
TotalLogicalReadCountsLong1

The total number of logical reads that were performed by all SQL statements in the query.

TotalPhysicalReadCountsLong1

The total number of physical reads that were performed by all SQL statements in the query .

ReportTimeString2011-05-30Z

The date on which the data report was generated.

MaxPhysicalReadCountsLong0

The largest number of physical reads that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
SQLServerTotalCpuTimeLong0

The total amount of CPU time that was used by all SQL statements in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
TotalIOWriteCountsLong0

The total number of I/O writes that were performed by all SQL statements in the query.

Note This parameter is returned only for instances that run SQL Server.
MaxRowsAffectedCountsLong0

The largest number of rows that were affected by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
AvgIOWriteCountsLong0

The average number of I/O writes per SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
MinPhysicalReadCountsLong0

The smallest number of physical reads that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
SlowLogIdLong26584213

The ID of the slow query log summary.

MaxExecutionTimeLong60

The longest execution duration of a specific SQL statement in the query. Unit: seconds.

AvgExecutionTimeLong1

The average execution duration per SQL statement in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
SQLServerAvgExecutionTimeLong0

The average execution duration per SQL statement in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
MaxIOWriteCountsLong0

The largest number of I/O writes that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
SQLServerAvgCpuTimeLong0

The average amount of CPU time per SQL statement in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
TotalLastRowsAffectedCountsLong0

The total number of rows that were affected by the last SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
AvgLogicalReadCountsLong0

The average number of logical reads per SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
SQLServerMinExecutionTimeLong0

The smallest execution duration of a specific SQL statement in the query. Unit: seconds.

Note This parameter is returned only for instances that run SQL Server.
SQLIdStrString521584

The ID of the SQL statement in the statistical template of slow query logs. This parameter is replaced by the SQLHASH parameter.

SQLServerTotalExecutionTimesLong1000

The total execution duration of all SQL statements in the query. This parameter is returned only for instances that run SQL Server. Unit: milliseconds.

AvgRowsAffectedCountsLong0

The average number of rows that were affected per SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
TotalRowsAffectedCountsLong0

The total number of rows that were affected by all SQL statements in the query.

AvgPhysicalReadCountsLong0

The average number of physical reads per SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.
MinLogicalReadCountsLong0

The smallest number of logical reads that were performed by a specific SQL statement in the query.

Note This parameter is returned only for instances that run SQL Server.

Examples

Sample requests

http(s)://rds.aliyuncs.com/?Action=DescribeSlowLogs
&DBInstanceId=rm-uf6wjk5xxxxxxx
&StartTime=2011-05-01Z
&EndTime=2011-05-30Z
&<Common request parameters>

Sample success response

XML format

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

<DescribeSlowLogsResponse>
    <EndTime>2011-05-30Z</EndTime>
    <StartTime>2011-05-30Z</StartTime>
    <RequestId>2553A660-E4EB-4AF4-A402-8AFF70A49143</RequestId>
    <PageRecordCount>10</PageRecordCount>
    <TotalRecordCount>5</TotalRecordCount>
    <DBInstanceId>rm-uf6wjk5xxxxxxx</DBInstanceId>
    <PageNumber>1</PageNumber>
    <Engine>MySQL</Engine>
    <Items>
        <MaxLastRowsAffectedCounts>0</MaxLastRowsAffectedCounts>
        <ReturnMaxRowCount>1</ReturnMaxRowCount>
        <SQLText>select id,name from tb_table</SQLText>
        <SQLServerMaxCpuTime>0</SQLServerMaxCpuTime>
        <CreateTime>2011-05-30Z</CreateTime>
        <AvgLastRowsAffectedCounts>0</AvgLastRowsAffectedCounts>
        <MinLastRowsAffectedCounts>0</MinLastRowsAffectedCounts>
        <ParseTotalRowCounts>1</ParseTotalRowCounts>
        <TotalLockTimes>0</TotalLockTimes>
        <MySQLTotalExecutionCounts>1</MySQLTotalExecutionCounts>
        <SQLServerMinCpuTime>0</SQLServerMinCpuTime>
        <SQLHASH>U2FsdGVkxxxx</SQLHASH>
        <MinIOWriteCounts>0</MinIOWriteCounts>
        <ParseMaxRowCount>1</ParseMaxRowCount>
        <MaxLogicalReadCounts>0</MaxLogicalReadCounts>
        <MySQLTotalExecutionTimes>1</MySQLTotalExecutionTimes>
        <SQLServerTotalExecutionCounts>1</SQLServerTotalExecutionCounts>
        <ReturnTotalRowCounts>1</ReturnTotalRowCounts>
        <MaxLockTime>0</MaxLockTime>
        <DBName>RDS_MySQL</DBName>
        <MinRowsAffectedCounts>0</MinRowsAffectedCounts>
        <TotalLogicalReadCounts>1</TotalLogicalReadCounts>
        <TotalPhysicalReadCounts>1</TotalPhysicalReadCounts>
        <ReportTime>2011-05-30Z</ReportTime>
        <MaxPhysicalReadCounts>0</MaxPhysicalReadCounts>
        <SQLServerTotalCpuTime>0</SQLServerTotalCpuTime>
        <TotalIOWriteCounts>0</TotalIOWriteCounts>
        <MaxRowsAffectedCounts>0</MaxRowsAffectedCounts>
        <AvgIOWriteCounts>0</AvgIOWriteCounts>
        <MinPhysicalReadCounts>0</MinPhysicalReadCounts>
        <SlowLogId>26584213</SlowLogId>
        <MaxExecutionTime>60</MaxExecutionTime>
        <AvgExecutionTime>1</AvgExecutionTime>
        <SQLServerAvgExecutionTime>0</SQLServerAvgExecutionTime>
        <MaxIOWriteCounts>0</MaxIOWriteCounts>
        <SQLServerAvgCpuTime>0</SQLServerAvgCpuTime>
        <TotalLastRowsAffectedCounts>0</TotalLastRowsAffectedCounts>
        <AvgLogicalReadCounts>0</AvgLogicalReadCounts>
        <SQLServerMinExecutionTime>0</SQLServerMinExecutionTime>
        <SQLIdStr>521584</SQLIdStr>
        <SQLServerTotalExecutionTimes>1000</SQLServerTotalExecutionTimes>
        <AvgRowsAffectedCounts>0</AvgRowsAffectedCounts>
        <TotalRowsAffectedCounts>0</TotalRowsAffectedCounts>
        <AvgPhysicalReadCounts>0</AvgPhysicalReadCounts>
        <MinLogicalReadCounts>0</MinLogicalReadCounts>
    </Items>
</DescribeSlowLogsResponse>

JSON format

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

{
  "EndTime" : "2011-05-30Z",
  "StartTime" : "2011-05-30Z",
  "RequestId" : "2553A660-E4EB-4AF4-A402-8AFF70A49143",
  "PageRecordCount" : 10,
  "TotalRecordCount" : 5,
  "DBInstanceId" : "rm-uf6wjk5xxxxxxx",
  "PageNumber" : 1,
  "Engine" : "MySQL",
  "Items" : [ {
    "MaxLastRowsAffectedCounts" : 0,
    "ReturnMaxRowCount" : 1,
    "SQLText" : "select id,name from tb_table",
    "SQLServerMaxCpuTime" : 0,
    "CreateTime" : "2011-05-30Z",
    "AvgLastRowsAffectedCounts" : 0,
    "MinLastRowsAffectedCounts" : 0,
    "ParseTotalRowCounts" : 1,
    "TotalLockTimes" : 0,
    "MySQLTotalExecutionCounts" : 1,
    "SQLServerMinCpuTime" : 0,
    "SQLHASH" : "U2FsdGVkxxxx",
    "MinIOWriteCounts" : 0,
    "ParseMaxRowCount" : 1,
    "MaxLogicalReadCounts" : 0,
    "MySQLTotalExecutionTimes" : 1,
    "SQLServerTotalExecutionCounts" : 1,
    "ReturnTotalRowCounts" : 1,
    "MaxLockTime" : 0,
    "DBName" : "RDS_MySQL",
    "MinRowsAffectedCounts" : 0,
    "TotalLogicalReadCounts" : 1,
    "TotalPhysicalReadCounts" : 1,
    "ReportTime" : "2011-05-30Z",
    "MaxPhysicalReadCounts" : 0,
    "SQLServerTotalCpuTime" : 0,
    "TotalIOWriteCounts" : 0,
    "MaxRowsAffectedCounts" : 0,
    "AvgIOWriteCounts" : 0,
    "MinPhysicalReadCounts" : 0,
    "SlowLogId" : 26584213,
    "MaxExecutionTime" : 60,
    "AvgExecutionTime" : 1,
    "SQLServerAvgExecutionTime" : 0,
    "MaxIOWriteCounts" : 0,
    "SQLServerAvgCpuTime" : 0,
    "TotalLastRowsAffectedCounts" : 0,
    "AvgLogicalReadCounts" : 0,
    "SQLServerMinExecutionTime" : 0,
    "SQLIdStr" : "521584",
    "SQLServerTotalExecutionTimes" : 1000,
    "AvgRowsAffectedCounts" : 0,
    "TotalRowsAffectedCounts" : 0,
    "AvgPhysicalReadCounts" : 0,
    "MinLogicalReadCounts" : 0
  } ]
}

Error codes

HTTP status codeError codeError messageDescription
400InvalidSearchTimeRangesearch 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.
400IO.ExceptionIO exception, retry later.The error message returned because I/O errors occurred.

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