The SQL audit feature lets you query and export SQL statement details, such as the database, status, and execution duration.
Prerequisites
-
You have enabled SQL Explorer and Stress Testing (New).
-
If you are a RAM user, you must have permissions to use the audit feature. You need one of the following: the AliyunDRDSReadOnlyWithSQLLogArchiveAccess permission, which can be granted by following the steps in Grant permissions to a RAM user, or a custom policy as described in Use a custom policy to authorize a RAM user to use the search (including export) features of SQL Explorer and audit.
Procedure
-
Click the audit tab and select the nodes to audit.
NoteClick service settings to configure the storage duration for SQL logs.
-
As needed, set query conditions or enable advanced query , and then click Query .
The following table describes the parameters.
Parameter
Description
Time range
The execution time range of the target SQL statements.
Keyword
One or more keywords contained in the target SQL statement. Separate multiple keywords with a space (
). Choose the logical operator to apply between keywords.-
OR: Returns SQL statements that contain at least one of the specified keywords.
-
AND: Returns only SQL statements that contain all of the specified keywords.
User
The name of the database account. To filter by multiple accounts, separate the account names with a space (
).Database
The name of the database. To filter by multiple databases, separate the database names with a space (
).Operation type
The SQL operation type. You can select one or more of the following types: SELECT, INSERT, UPDATE, DELETE, LOGIN, LOGOUT, MERGE, ALTER, CREATE, DROP, SET, DESC, REPLACE, CALL, BEGIN, DESCRIBE, ROLLBACK, FLUSH, USE, SHOW, START, COMMIT, RENAME, and TRUNCATE.
Client IP address
The IP address of the remote client that executes the SQL statement. To filter by multiple IP addresses, separate them with a space (
).Execution status
The execution status of the SQL statement. You can select successful, failed, or both.
Execution duration
The execution duration of the SQL statement in milliseconds (ms). You can specify a range to filter the results.
Updated/returned rows
The number of rows updated or returned by the SQL statement. You can specify a range to filter the results.
Physical SQL statements
The number of physical SQL statements executed.
Tracking ID
The ID for a request from a compute node to a data node. You can obtain this ID from the log list in the query results.
Transaction ID
The transaction ID generated by the SQL execution. You can obtain this ID from the log list in the query results.
SQL ID
The SQL template ID. To filter by multiple SQL IDs, separate them with a space (
). You can obtain SQL IDs from SQL Explorer. -
-
(Optional) Click Export and select the desired export fields to export the SQL log records. You can set an export time range to export SQL records from a larger time range.
NoteClick view export list to view recent export tasks.