Queries the logs generated by the SQL explorer (SQL audit) feature on an ApsaraDB for RDS instance.

Before you call this operation, make sure that the instance is running one of the following database engines and versions:

  • MySQL
  • SQL Server
  • PostgreSQL
  • PPAS

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 DescribeSQLLogRecords

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

DBInstanceId String Yes rm-uf6wjk5xxxxxxx

The ID of the instance.

EndTime String Yes 2011-06-11T15:00: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:mm:ssZ format. The time must be in UTC.

StartTime String Yes 2011-06-01T15:00:00Z

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

ClientToken String No ETnLKlblzczshOTUbOCzxxxxxxx

The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must ensure that it is unique among different requests. The token can only contain ASCII characters and cannot exceed 64 characters in length.

SQLId Long No 25623548

The unique ID of the specific SQL statement to query.

QueryKeywords String No rds

The keyword to use for the query. If you enter more than one keyword, separate them with spaces. Up to 10 keywords are allowed in a single request.

Database String No Database

The name of the specific database to query. If you specify this parameter, this operation will return only the logs that are generated for the specified database. If you do not specify this parameter, this operation will return the logs that are generated for all of the databases on the instance.

User String No user

The username of the RAM user to query. If you specify this parameter, this operation will return only the logs that are generated for the specified RAM user. If you do not specify this parameter, this operation will return the logs that are generated for all of the RAM users on the instance.

Form String No Stream

Specifies whether to generate SQL audit log files or return SQL audit log records. Valid values:

  • File: This operation will trigger the generation of SQL audit log files and return only the common parameters. You must call the DescribeSQLLogFiles operation to obtain the URLs from which you can download the files.
  • Stream: This operation will return SQL audit log records. This value is the default value.
PageSize Integer No 30

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

PageNumber Integer No 1

The number of the page to return. Pages start from page 1.

Default value: 1.

Response parameters

Parameter Type Example Description
RequestId String 08A3B71B-FE08-4B03-974F-CC7EA6DB1828

The ID of the request.

TotalRecordCount Long 100

The total number of entries returned.

PageNumber Integer 1

The page number of the returned page.

PageRecordCount Integer 30

The number of entries returned on the current page.

Items Array

An array that consists of SQL audit log entries.

DBName String testDB

The name of the database.

AccountName String accounttest

The username of the account who executed the SQL statement.

HostAddress String 192.168.0.121

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

SQLText String update test.zxb set id=0 limit 1

The SQL statement recorded.

TotalExecutionTimes Long 600

The time taken to execute the SQL statement. Unit: microseconds.

ReturnRowCounts Long 30

The number of entries returned for the SQL statement.

ExecuteTime String 2011-06-11T15:00:23Z

The time when the SQL statement was executed. The time follows the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time is displayed in UTC.

ThreadID String 1025865428

The ID of the thread.

Examples

Sample requests

http(s)://rds.aliyuncs.com/? Action=DescribeSQLLogRecords
&DBInstanceId=rm-uf6wjk5xxxxxx
&StartTime=2011-06-01T15:00:00Z
&EndTime=2011-06-11T15:00:00Z
&<Common request parameters>

Sample success responses

XML format

<DescribeSQLLogRecordsResponse>
      <PageNumber>1</PageNumber>
      <TotalRecordCounts>1</TotalRecordCounts>
      <ItemsCounts>1</ItemsCounts>
      <SQLItems>
            <SQLItem>
                  <DBName>test</DBName>
                  <AccountName>accounttest</AccountName>
                  <HostAddress>192.168.0.121</HostAddress>
                  <SQLText>update test.zxb set id=0 limit 1</SQLText>
                  <TotalExecutionTimes>12</TotalExecutionTimes>
                  <ReturnRowCounts>34</ReturnRowCounts>
                  <ExecuteTime>2011-06-11T15:00:23Z</ExecuteTime>
            </SQLItem>
      </SQLItems>
      <RequestId>08A3B71B-FE08-4B03-974F-CC7EA6DB1828</RequestId>
</DescribeSQLLogRecordsResponse>

JSON format

{
"PageNumber":1,
"TotalRecordCounts":1,
"ItemsCounts":1,
"SQLItems":
{"SQLItem":
[
{
"DBName":"test",
"AccountName":"accounttest",
"HostAddress":"192.168.0.121",
"SQLText":"update test.zxb set id=0 limit 1",
"TotalExecutionTimes":12,
"ReturnRowCounts":34,
"ExecuteTime":"2011-06-11T15:00:23Z"
}
]
},
"RequestId": "08A3B71B-FE08-4B03-974F-CC7EA6DB1828"
}

Error codes

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