You can call the DescribeSQLLogRecords operation to query the logs that are generated by the SQL Explorer (SQL Audit) feature on an ApsaraDB RDS instance.

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

  • 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 ISO8601 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 ISO8601 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 SQL statement to query.

QueryKeywords String No rds

The keywords that are used for the query. If you enter more than one keyword, separate them with spaces. A maximum of 10 keywords are allowed.

Database String No Database

The name of the database to query. If you specify this parameter, this operation returns only the log entries that are generated for the specified database. If you do not specify this parameter, this operation returns the log entries that are generated for all of the databases on the instance.

User String No user

The username of the database account to query. If you specify this parameter, this operation returns only the log entries that are generated for the specified database account. If you do not specify this parameter, this operation returns the log entries that are generated for all of the database accounts on the instance.

Form String No Stream

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

  • File: This operation triggers the generation of SQL log files and returns only the common parameters. You must call the DescribeSQLLogFiles operation to obtain the download URLs of the files.
  • Stream: This operation returns SQL log entries. 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
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 SQL log entries returned on the current page.

Items Array

An array that consists of SQL log entries.

SQLRecord
DBName String testDB

The name of the database on which the SQL statement was executed.

AccountName String accounttest

The username of the account that was used to execute the SQL statement.

HostAddress String 192.168.0.121

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

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

The SQL statement that was recorded in the SQL log entry.

TotalExecutionTimes Long 600

The execution duration of the SQL statement. Unit: microseconds.

ReturnRowCounts Long 30

The number of entries returned.

ThreadID String 1025865428

The ID of the thread that was invoked to execute 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.

RequestId String 08A3B71B-FE08-4B03-974F-CC7EA6DB1828

The ID of the request.

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.