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
Error 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.
NoteIf 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 Simple Log Service console.
In the Log Application section, select the Audit & Security tab and 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.
NoteFor more information about central projects, see Project.
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, Error 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.
After you complete the configurations, click OK.
NoteYou 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 is deployed, 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 Add tags.
Click Save in the upper-right corner of the dashboard page.
NoteThe 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 Simple Log Service console.
On the Global Configurations tab, click the created central project. The project name is in the
slsaudit-center-<Alibaba Cloud account ID>-<region ID>
format.Choose the Audit Query tab and click PolarDB to expand the Logstore and view log details.
Disable PolarDB log collection
Disable the PolarDB log collection feature. For more information, see What to do next.
NoteAfter 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=<project name> --region-endpoint=<region ID>.log.aliyuncs.com
ImportantThis operation deletes all data from a project. Proceed with caution.
Log fields
For more information, see The fields of PolarDB for MySQL logs.