All Products
Search
Document Center

PolarDB:Subscribe to the PolarDB for MySQL cluster logs

Last Updated:Apr 22, 2024

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.

    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 Simple Log Service console.

  2. In the Log Application section, select the Audit & Security tab and click Log Audit Service.

    image

  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. 全局配置

      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.

    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, Error Logs, or Performance Logs.

      image

    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.

      After you complete the configurations, click OK.

      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 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.

    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.

      image

  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 Simple Log Service console.

  2. 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.

    image

  3. Choose the Audit Query tab and click PolarDB to expand the Logstore and view log details.

    image

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=<project name> --region-endpoint=<region ID>.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.