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

Description

Before you call the DescribeAuditLogRecords operation, make sure that SQL audit is enabled. 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.

You can query SQL audit logs only when SQL audit is enabled. You can query SQL audit logs only within the last 30 days. If SQL audit was disabled and re-enabled, you can query only SQL audit logs from the time when SQL audit was re-enabled.

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
DBClusterId String Yes am-t4nj8619bz2w3****

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.
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 2021-12-08T09:53Z

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 You can query SQL audit logs only when SQL audit is enabled. You can query SQL audit logs only for 30 days. If SQL audit was enabled and then disabled and re-enabled, you can query only SQL audit logs from the time SQL audit was re-enabled.
EndTime String Yes 2021-12-09T09:53Z

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.
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 statements to query.

SqlType String No SELECT

The type of the SQL statement. Valid values:

  • DELETE
  • SELECT
  • UPDATE
  • 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
  • false
HostAddress String No 100.104.XXX.XXX:43908

The IP address and port number of the client that is used to execute the SQL statement. Specify the value of this parameter in the IP address:Port number format.

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_user

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
    Note If you do not specify this parameter, the value 10 is used.
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.

Action String Yes DescribeAuditLogRecords

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

Response parameters

Parameter Type Example Description
TotalCount String 1

The total number of entries returned.

PageSize String 10

The number of entries returned on each page.

RequestId String 8A564B7F-8C00-43C0-8EC5-919FBB70573

The ID of the request.

PageNumber String 1

The page number of the returned page.

DBClusterId String am-t4nj8619bz2w3****

The ID of the cluster.

Items Array of SlowLogRecord

Details of the SQL audit logs.

HostAddress String 100.104.XXX.XXX:43908

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

Succeed String true

Indicates whether the SQL statement was successfully executed. Valid values:

  • true
  • false
SQLText String SELECT * FROM tb_courses

Details of the SQL statement.

TotalTime String 216

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

ConnId String None

This parameter does not take effect.

DBName String adb_test

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

SQLType String SELECT

The type of the SQL statement.

ExecuteTime String 2021-12-08 20:52:02

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

ProcessID String 202106081752021720161662490345362390

The ID of the task.

Examples

Sample requests

http(s)://adb.aliyuncs.com/?Action=DescribeAuditLogRecords
&DBClusterId=am-t4nj8619bz2w3****
&RegionId=cn-hangzhou
&StartTime=2021-12-08T09:53Z
&EndTime=2021-12-09T09:53Z
&DBName=adb_demo
&QueryKeyword=adb
&SqlType=SELECT
&Succeed=true
&HostAddress=100.104.XXX.XXX:43908
&OrderType=asc
&User=test_user
&Order=[{"Field":"ExecuteTime","Type":"Desc"},{"Field":"HostAddress","Type":"Asc"}]
&PageSize=10
&PageNumber=1
&<Common request parameters>

Sample success responses

XML format

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

<DescribeAuditLogRecordsResponse>
    <TotalCount>1</TotalCount>
    <PageSize>10</PageSize>
    <RequestId>8A564B7F-8C00-43C0-8EC5-919FBB70573</RequestId>
    <PageNumber>1</PageNumber>
    <DBClusterId>am-t4nj8619bz2w3****</DBClusterId>
    <Items>
        <HostAddress>100.104.XXX.XXX:43908</HostAddress>
        <Succeed>true</Succeed>
        <SQLText>SELECT * FROM tb_courses</SQLText>
        <TotalTime>216</TotalTime>
        <ConnId>None</ConnId>
        <DBName>adb_test</DBName>
        <SQLType>SELECT</SQLType>
        <ExecuteTime>2021-12-08 20:52:02</ExecuteTime>
        <ProcessID>202106081752021720161662490345362390</ProcessID>
    </Items>
</DescribeAuditLogRecordsResponse>

JSON format

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

{
  "TotalCount" : 1,
  "PageSize" : 10,
  "RequestId" : "8A564B7F-8C00-43C0-8EC5-919FBB70573",
  "PageNumber" : 1,
  "DBClusterId" : "am-t4nj8619bz2w3****",
  "Items" : {
    "HostAddress" : "100.104.XXX.XXX:43908",
    "Succeed" : true,
    "SQLText" : "SELECT * FROM tb_courses",
    "TotalTime" : 216,
    "ConnId" : "None",
    "DBName" : "adb_test",
    "SQLType" : "SELECT",
    "ExecuteTime" : "2021-12-08 20:52:02",
    "ProcessID" : 2.0210608175202173E35
  }
}

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.