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

  1. Log on to the Log Service console.
  2. In the Log Application section, click Log Audit Service.
  3. 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.
  4. Choose Access to Cloud Products > Global Configurations. Then perform the following steps:
    1. 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. Global configurations
      The system automatically creates a central project, and the collected logs you configure in the following steps are delivered to the central project.
      • 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).
    2. 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. PolarDB logs
    3. 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.
    4. 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.
  5. In the dialog box that appears, click Go to Access Status to view the access status of the log.
    You can also choose Access to Cloud Products > Status Dashboard in the left-side navigation pane to check whether log collection is enabled for the log types.

View collected PolarDB logs

  1. Log on to the Log Service console.
  2. On the Global Configurations tab, click the created central project. The project name is in the slsaudit-center-- format.
    Central project
  3. View log details.
    • View audit logs or slow query logs
      1. On the Logstores tab, click the Arrow icon on the left of polardb_log to expand the Logstore. polardb_log
      2. Click the Query and analysis icon on the right side of the page to view the log details. polardb_log
    • View performance logs
      1. In the left-side navigation pane, click the Time Series Storage icon. View logs
      2. On the Logstores tab, click the Arrow icon on the left of polardb_metrics to expand the Logstore.
      3. Click the Query and analysis icon on the right side of the page to view the log details.

Disable PolarDB log collection

  1. 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.
  2. Open the Cloud Shell.
  3. 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.

Log fields

For more information, see The fields of PolarDB for MySQL logs.