Queries the SQL audit logs of an AnalyticDB for MySQL cluster.

Description

Before you call the DescribeAuditLogRecords operation to query the SQL audit logs of an AnalyticDB for MySQL cluster, you must enable SQL audit for the cluster. You can call the DescribeAuditLogConfig operation to query the status of SQL audit. If SQL audit is disabled, you can call the ModifyAuditLogConfig operation to enable SQL audit.

SQL audit logs can be queried only when SQL audit is enabled. Only SQL audit logs within the last 30 days can be queried. If SQL audit was disabled and re-enabled, only SQL audit logs from the time when SQL audit was re-enabled can be queried.

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 No DescribeAuditLogRecords

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

DBClusterId String Yes am-bp1jj9xqft1po****

The ID of the cluster.

Note You can call the DescribeDBClusters operation to query the details of all AnalyticDB for MySQL clusters within a specific region, including cluster IDs.
EndTime String Yes 2022-01-23T22:18Z

The end of the time range to query. Specify the time in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

Note
  • The end time must be later than the start time.
  • The interval between the start time and the end time cannot exceed 24 hours.
RegionId String Yes cn-hangzhou

The ID of the region.

Note You can call the DescribeRegions operation to query the regions and zones supported by AnalyticDB for MySQL, including region IDs.
StartTime String Yes 2022-01-23T02:18Z

The beginning of the time range to query. Specify the time in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

Note SQL audit logs can be queried only when SQL audit is enabled. Only SQL audit logs within the last 30 days can be queried. If SQL audit was disabled and re-enabled, only SQL audit logs from the time when SQL audit was re-enabled can be queried.
DBName String No adb_demo

The name of the database on which you want to execute the SQL statement.

QueryKeyword String No adb

The keywords that are included in the SQL statement to query.

SqlType String No SELECT

The type of the SQL statement. Valid values:

  • DELETE
  • DROP
  • SELECT
  • INSERT
  • UPDATE
  • ALTER
  • INSERT_INTO_SELECT
Note You can query only one type of SQL statements at a time. If this parameter is left empty, the SELECT SQL statements are queried.
Succeed String No true

The execution result of the SQL statement that you want to query. Valid values:

  • true: The SQL statement is successfully executed.
  • false: The SQL statement fails to be executed.
HostAddress String No 100.104.XX.XX:43908

The IP address and port number of the client that is used to execute the SQL statement.

OrderType String No asc

The sorting sequence of the retrieved entries. Valid values:

  • asc: sorts the retrieved entries by time in ascending order.
  • desc: sorts the retrieved entries by time in descending order.
User String No test

The name of the user who executes the SQL statement.

Order String No [{"Field":"ExecuteTime","Type":"Desc"},{"Field":"HostAddress","Type":"Asc"}]

The order in which specified fields are sorted. Specify this parameter as an ordered JSON array that consists of the Field and Type fields.

  • Field specifies the field used to sort the retrieved entries. Valid values:
    • HostAddress: the IP address of the client that is used to connect to the database.
    • Succeed: specifies whether the SQL statement is successfully executed.
    • TotalTime: the total amount of time consumed to execute the SQL statement.
    • DBName: the name of the database on which the SQL statement is executed.
    • SQLType: the type of the SQL statement.
    • User: the username that is used to execute the SQL statement.
    • ExecuteTime: the time to start executing the SQL statement.
  • Type specifies the sorting sequence. Valid values:
    • Desc: descending order.
    • Asc: ascending order.
PageSize Integer No 10

The number of entries to return on each page. Valid values:

  • 10
  • 30
  • 50
  • 100

Default value: 10.

PageNumber Integer No 1

The number of the page to return. The value must be an integer that is greater than 0. Default value: 1.

Response parameters

Parameter Type Example Description
DBClusterId String am-bp1jj9xqft1po****

The ID of the cluster.

Items Array of SlowLogRecord

Details of the SQL audit logs.

ConnId String None

This parameter is unavailable.

DBName String adb_demo

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

ExecuteTime String 2022-01-23 16:05:08

The start time of the execution of the SQL statement. The time is displayed in the yyyy-MM-dd HH:mm:ss format.

HostAddress String 100.104.XX.XX:43908

The IP address and port number of the client that is used to execute the SQL statement.

ProcessID String 2022012316100917201616624903453108504

The ID of the task.

SQLText String SELECT * FROM tb_courses

Details of the SQL statement.

SQLType String SELECT

The type of the SQL statement.

Succeed String true

Indicates whether the SQL statement was successfully executed.

  • true: The SQL statement was successfully executed.
  • false: The SQL statement failed to be executed.
TotalTime String 20

The amount of time consumed to execute the SQL statement. Unit: milliseconds.

User String test

The name of the user who executed the SQL statement.

PageNumber String 1

The number of the returned page.

PageSize String 30

The number of entries returned on each page.

RequestId String 1AD222E9-E606-4A42-BF6D-8A4442913CEF

The ID of the request.

TotalCount String 300

The total number of entries returned.

Examples

Sample requests

http(s)://adb.aliyuncs.com/?Action=DescribeAuditLogRecords
&DBClusterId=am-bp1jj9xqft1po****
&EndTime=2022-01-23T22:18Z
&RegionId=cn-hangzhou
&StartTime=2022-01-23T02:18Z
&<Common request parameters>

Sample success responses

XML format

<TotalCount>300</TotalCount>
<RequestId>1AD222E9-E606-4A42-BF6D-8A4442913CEF</RequestId>
<PageSize>30</PageSize>
<PageNumber>1</PageNumber>
<DBClusterId>am-bp1jj9xqft1po****</DBClusterId>
<Items>
    <User>test</User>
    <ConnId>None</ConnId>
    <ExecuteTime>2022-01-23 16:05:08</ExecuteTime>
    <TotalTime>20</TotalTime>
    <DBName>adb_demo</DBName>
    <ProcessID>2022012316100917201616624903453108504</ProcessID>
    <SQLType>SELECT</SQLType>
    <HostAddress>100.104.XXX.XXX:43908</HostAddress>
    <SQLText>SELECT * FROM tb_courses</SQLText>
    <Succeed>true</Succeed>
</Items>

JSON format

{
    "TotalCount": 300,
    "RequestId": "1AD222E9-E606-4A42-BF6D-8A4442913CEF",
    "PageSize": 30,
    "PageNumber": 1,
    "DBClusterId": "am-bp1jj9xqft1po****",
    "Items": {
        "User": "test",
        "ConnId": "None",
        "ExecuteTime": "2022-01-23 16:05:08",
        "TotalTime": 20,
        "DBName": "adb_demo",
        "ProcessID": 2.022012316100917e+36,
        "SQLType": "SELECT",
        "HostAddress": "100.104.XX.XX:43908",
        "SQLText": "SELECT * FROM tb_courses",
        "Succeed": true
    }
}

Error codes

HTTP status code Error code Error message Description
404 InvalidDBCluster.NotFound The DBClusterId provided does not exist in our records. The error message returned because the specified DBClusterId parameter does not exist. Check whether the cluster ID is valid.

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