PolarDB provides a log subscription feature to help enterprises manage their logs. This feature
is powered by Alibaba Cloud Log Service and allows you to deliver all PolarDB for MySQL cluster logs to the central projects of Log Service for centralized management. This
topic describes how to subscribe to and view PolarDB for MySQL cluster logs.
Usage notes
- Your PolarDB cluster must be a PolarDB for MySQL cluster.
- The PolarDB log collection feature can collect only the following types of logs:
- Audit logs
- Slow query logs
- Performance logs
- To collect the audit logs of a cluster, you must enable the SQL Explorer feature for
the cluster from which you want to collect logs. You are charged for SQL Explorer
based on the size of the storage space that is used by audit logs. For more information,
see SQL Explorer.
Note If you need to collect only slow query logs or performance logs, you do not need to
enable SQL Explorer.
Enable PolarDB log collection
- Log on to the Log Service console.
- In the Log Application section, click Log Audit Service.
- Configure authorization for log collection and synchronization.
- If logs are collected under the same account, follow the on-screen instructions to
perform the required authorization operations. For more information, see the "Initially configure Log Audit Service" section of the Enable log collection topic.
- For information about multi-account log collection, see Custom authentication mode.
- Choose . Then perform the following steps:
- In the Region of the Central Project drop-down list, select the region in which you want to create a central project to
store the collected logs.

The system automatically creates a central project, and the collected logs you configure
in the following steps are delivered to the central project.
Note
- For more information about central projects, see Project.
- The available regions include China (Beijing), China (Hohhot), China (Hangzhou), China
(Shanghai), China (Shenzhen), Japan (Tokyo), and Singapore (Singapore).
- Select the types of logs that you want to collect by using the PolarDB log collection feature. You can select Audit Logs, Slow Query Logs, or Performance Logs.

- Click Collection Policy on the right-hand side of the log that you want to collect. In the Collection Policy Configuration dialog box, add the region where your cluster resides to the policy. If you do not
add any region, the system creates a Logstore for each region. For more information,
see Logstore and Configure log collection policies.
Note You can configure collection policies as needed. You can configure the following parameters
in log collection policies for
PolarDB for MySQL clusters:
- account.id: the ID of the Alibaba Cloud account to which your PolarDB for MySQL cluster belongs.
- region: the region where your PolarDB for MySQL cluster resides, for example, cn-hangzhou.
- cluster.id: the ID of your PolarDB for MySQL cluster.
- cluster.name: the name of your PolarDB for MySQL cluster.
- cluster.db_type: the types of databases that are compatible with your PolarDB for MySQL cluster. Only MySQL is supported.
- cluster.db_version: the database version. Valid values: 8.0, 5.7, and 5.6.
- tag.*: the name of the tag. You can replace the asterisk (*) in the tag.* parameter
with a custom tag name. For more information about PolarDB for MySQL cluster tags, see Bind a tag.
- Click Save in the upper-right corner of the dashboard page.
Note The changes take effect after 2 minutes. If an exception occurs, follow the on-screen
instructions to modify the configuration.
- In the dialog box that appears, click Go to Access Status to view the access status of the log.
You can also choose in the left-side navigation pane to check whether log collection is enabled for the
log types.
View collected PolarDB logs
- Log on to the Log Service console.
- On the Global Configurations tab, click the created central project. The project name is in the
slsaudit-center--
format.
- View log details.
- View audit logs or slow query logs
- On the Logstores tab, click the
icon on the left of polardb_log to expand the Logstore. 
- Click the
icon on the right side of the page to view the log details. 
- View performance logs
- In the left-side navigation pane, click the
icon. 
- On the Logstores tab, click the
icon on the left of polardb_metrics to expand the Logstore.
- Click the
icon on the right side of the page to view the log details.
Disable PolarDB log collection
- Disable the PolarDB log collection feature. For more information, see What to do next.
Note After you modify the configuration, the configuration will take effect in about 2
minutes.
- Open the Cloud Shell.
- Execute the following statement to delete a Logstore:
aliyunlog log delete_project --project_name= --region-endpoint=.log.aliyuncs.com
Important This operation deletes all data from a project. Proceed with caution.
Was this helpful?