Overview
This interface is used to query OceanBase SQL audit logs.
API details
Constraints
The caller must have an AccessKey for accessing APIs of OceanBase Cloud. For information about how to obtain the AccessKey ID and AccessKey secret, see Manage AccessKeys.
Request path
GET /api/v2/instances/{instanceId}/tenants/{tenantId}/sqlaudit/data
Request parameters
Query
| Name | Type | Required | Description | Example value |
|---|---|---|---|---|
| instanceId | String | Yes | OceanBase cluster ID. | ob317v4uif**** |
| tenantId | String | Yes | Tenant ID. | t33h8y08k**** |
Body
| Name | Type | Required? | Description | Example Value |
|---|---|---|---|---|
| startTime | String | Required | Start time. UTC time is supported. The value is in the format of YYYY-MM-DDThh:mm:ssZ. | 2025-03-20T08:19:41Z |
| endTime | String | No | The end time, in UTC. This time must be in the format of YYYY-MM-DDThh:mm:ssZ. | 2025-03-20T08:49:41Z |
| dbName | String | No | The database name, which can be obtained from topSQL/slowSQL/suspicious SQL statements. | db_test |
| clientIp | String | No | The IP address of the client. | 10.xx.xx.xx |
| executeTimeMax | double | No | The maximum execution time, in milliseconds. | 300 |
| executeTimeMin | double | No | The minimum execution time, in milliseconds. | 200 |
| nodeIp | String | No | The execution node list | 3a974b72-****-****-****-37e1******** |
| operatorType | String | None | The SQL statement type, such as SELECT or CREATE | SELECT |
| pageNumber | integer | N/A | The page number for pagination | 1 |
| pageSize | integer | No | The size of the page | 10 |
| scanRowsMax | integer | No | The maximum number of rows to scan. | 5 |
| scanRowsMin | integer | No | The minimum number of rows to scan | 1 |
| userName | String | No | Username | test_user |
| searchKeyWord | String | N/A | Query keyword | update |
| searchKeyWorkMethod | String | No | Logical operator for query | and |
Response parameters
| Name | Type | Description | Example value |
|---|---|---|---|
| affectedRows | integer | Number of rows affected | 0 |
| clientIp | string | Client IP | 10.xx.xx.xx |
| databaseName | string | Database name | default_database |
| elapsedTime | double | Elapsed time in milliseconds | 19.0 |
| isSuccess | boolean | Whether the operation succeeded | 1 |
| operatorType | String | SQL statement type | SELECT |
| querySQL | String | SQL statement text | SELECT table_schema as schema_name, 'VIEW' as type, table_name as name FROM information_schema.tables where table_type = 'VIEW' ORDER BY schema_name, name |
| requestTime | String | Request time | 2025-03-20T08:43:41Z |
| retCode | boolean | Execution result | 0 |
| scanRows | integer | Number of rows scanned | 3519 |
| sqlID | String | SQL ID | D56D******** |
| userClientIp | String | Client IP | 10.xx.xx.xx |
| userName | String | Username | test_user |
Examples
Request example
curl --digest -u 'ak:sk' \
--request GET \
--url https://api-cloud.oceanbase.com/api/v2/instances/{instanceId}/tenants/{tenantId}/sqlaudit/data
-H 'X-Ob-Project-Id: <Project ID>'
-G -d 'UID=xxx' -d 'callerType=xxx' -d 'accessKeyId=xxx' -d 'securityToken=xxx' -d 'callerUid=xxx' -d 'callerBid=xxx' -d 'stsTokenCallerUid=xxx' -d 'stsTokenCallerBid=xxx' -d 'acceptLanguage=xxx' -d 'pageNumber=xxx' -d 'pageSize=xxx' -d 'mergedCallerBid=xxx' -d 'instanceId=xxx' -d 'tenantId=xxx' -d 'startTime=xxx' -d 'endTime=xxx' -d 'nodeIp=xxx' -d 'dbName=xxx' -d 'searchKeyWord=xxx' -d 'searchKeyWordMethod=xxx' -d 'userName=xxx' -d 'operatorType=xxx' -d 'clientIp=xxx' -d 'executeTimeMin=xxx' -d 'executeTimeMax=xxx' -d 'scanRowsMin=xxx' -d 'scanRowsMax=xxx' -d 'sortField=xxx' -d 'sortType=xxx'
Note
- A project ID uniquely identifies a project. For information about how to obtain the project ID of an instance, see Manage projects.
- Make sure that the ID of the project to which the instanceId belongs is the same as the specified project ID.
Response example
JSON format
{
"data": {
"sqlAuditDTOList": [
{
"affectedRows": 0,
"clientIp": "",
"databaseName": "default_database",
"elapsedTime": 19.0,
"isSuccess": 1,
"key": 1,
"operatorType": "SELECT",
"querySQL": "SELECT table_schema as schema_name, 'VIEW' as type, table_name as name FROM information_schema.tables where table_type = 'VIEW' ORDER BY schema_name, name",
"requestTime": "2025-03-20T08:43:41Z",
"requestTimestamp": 0,
"retCode": 0,
"scanRows": 3519,
"sqlID": "D56D********",
"userClientIp": "10.xx.xx.xx",
"userName": "test_user"
},
"success": true
]
}
}