The search feature is used to query SQL statements and export related information such as the databases on which the SQL statements are executed, the status of the SQL requests, and the execution duration of each SQL statement. This topic describes how to use the search feature.
Prerequisites
- The SQL Insight and Stress Testing feature is enabled. If the feature is disabled, you can click Enable to enable it.
- The AliyunDRDSReadOnlyWithSQLLogArchiveAccess policy is attached to the RAM user if you use the Search feature as a RAM user. For more information about how to grant permissions to a RAM user, see Grant permissions to a RAM user. Note You can also create a custom policy to grant the RAM user the permissions to use the search and export features. For more information, see Use custom policies to grant a RAM user the permissions to use the search and export features in the SQL Explorer and Audit module.
Procedure
- Log on to the PolarDB for Xscale console.
- In the top navigation bar, select the region where the target instance is located.
- On the Instances page, click the PolarDB-X 2.0 tab.
- Find the target instance and click its ID.
- In the left-side navigation pane, choose . Note You can click Service Settings to specify the retention period of SQL logs.
- On the page that appears, click the Search tab and specify query conditions. The following table describes the parameters that you can specify as query conditions.
Parameter Description Time Range Specify the time range during which the SQL statements executed are queried.
The maximum time range that is allowed for an online query is 24 hours. This is because the SQL Explorer feature logs a large number of SQL statements. These logs can be used to trace all operations that are performed on your database instance. If the time range for an online query exceeds 24 hours, the query can take an extended period of time to run and may even time out.Note If you want to query SQL statements over a time range that exceeds 24 hours, we recommend that you asynchronously export SQL logs as a file and download the file to your on-premises machine.Keyword You can specify multiple keywords. Fuzzy queries are not supported. Multiple keywords must be separated by spaces. Note Each keyword must contain at least four characters.User You can specify multiple usernames that are separated by spaces. Example: user1 user2 user3. Database You can specify multiple database names that are separated by spaces. Example: DB1 DB2 DB3. Operation Type Select the operation types that you want to query. You can select one or more operation types. Note You can click Enable Advanced Query to specify more parameters to further refine the query. - Click Query. Then, you can view the information about queried SQL statements in the Logs section. Note
- You can click Export to export the logs. In the Export SQL Records dialog box, you can select the fields that you want to export from Exported Fields. You can configure the Export Time Range parameter to export information about SQL statements within longer time ranges.
- You can click View Exported Logs to view recent export tasks.