You can call the DescribeSQLLogRecords operation to query the logs that are generated by the SQL Explorer (SQL Audit) feature for 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
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | DescribeSQLLogRecords |
The operation that you want to perform. Set the value to DescribeSQLLogRecords. |
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. |
DBInstanceId | String | Yes | rm-uf6wjk5xxxxxxx |
The ID of the instance. |
SQLId | Long | No | 25623548 |
The unique ID of the SQL statement that you want to query. |
QueryKeywords | String | No | table_name |
The keyword that is used for the query.
|
StartTime | String | Yes | 2011-06-01T15:00:00Z |
The beginning of the time range to query. You can query the logs that are generated within the most recent 30 days. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. |
Database | String | No | Database |
The name of the database that you want to query. You can enter only one database name. If you specify this parameter, this operation returns only the logs that are generated for the specified database. If you do not specify this parameter, this operation returns the logs that are generated for all databases on the instance. |
User | String | No | user |
The username of the account that you want to query. You can enter only one username. If you specify this parameter, this operation returns only the logs that are generated for the specified account. If you do not specify this parameter, this operation returns the logs that are generated for all accounts on the instance. |
Form | String | No | Stream |
Specifies whether to generate an SQL audit log file or return SQL audit log entries. Valid values:
|
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 30 days. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. |
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. Valid values: any non-zero positive integer. Default value: 1. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
RequestId | String | 08A3B71B-FE08-4B03-974F-CC7EA6DB1828 |
The ID of the request. |
PageNumber | Integer | 1 |
The number of the returned page. |
PageRecordCount | Integer | 30 |
The number of SQL audit log entries on the current page. |
TotalRecordCount | Long | 100 |
The total number of entries. |
Items | Array of SQLRecord |
An array that consists of the details about each SQL audit log entry. |
|
SQLRecord | |||
HostAddress | String | 192.168.0.121 |
The IP address of the client that is connected to the instance. |
SQLText | String | update test.zxb set id=0 limit 1 |
The SQL statement that was executed in the query. |
ReturnRowCounts | Long | 30 |
The number of SQL audit log entries that are returned. |
DBName | String | testDB |
The name of the database that is recorded in the SQL audit log entry. |
ExecuteTime | String | 2011-06-11T15:00:23Z |
The time at which the recorded 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 that is recorded in the SQL audit log entry. |
TotalExecutionTimes | Long | 600 |
The execution duration of the recorded SQL statement. Unit: microseconds. |
AccountName | String | accounttest |
The username of the account that is recorded in the SQL audit log entry. |
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
HTTP/1.1 200 OK
Content-Type:application/xml
<?xml version="1.0" encoding="UTF-8" ?>
<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
HTTP/1.1 200 OK
Content-Type:application/json
{
"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.