This topic describes how to delete the binary log files of an ApsaraDB RDS for MySQL instance. You can configure rules based on which ApsaraDB RDS automatically deletes binary log files. You can also manually delete binary log files.

Binary log files are generated on your RDS instance in real time. The rules based on which binary log files are generated varies based on the RDS edition:
  • RDS Basic Edition or RDS High-availability Edition: When the size of a binary log file exceeds 512 MB512 MB or the length of time during which binary log data continues to be written to a binary log file exceeds 6 hours, a new binary log file is generated.
  • RDS Enterprise Edition: If the size of a binary log file exceeds 512 MB,512 MB a new binary log file is generated.
After binary log files are deleted, the storage that is occupied by the binary log files is released.
Note After binary log files are deleted from an RDS instance, the size of the log backup files of the RDS instance does not decrease and you can still restore the data of the RDS instance to a specific point in time. Take note that you can restore the data of an RDS instance to a specific point in time only after you enable the log backup feature for the RDS instance.

Procedure

To configure rules based on which ApsaraDB RDS automatically deletes the binary log files of an RDS instance, perform the following steps:
  1. Visit the RDS instance list, select a region above, and click the target instance ID.
  2. In the left-side navigation pane, click Backup and Restoration.
  3. On the Backup Settings tab, click Edit in the Local Log Backup Settings section to configure the rules.
    • Rule 1: ApsaraDB RDS deletes the binary log files whose retention period exceeds the maximum retention period that is specified by the Retention Period parameter. By default, the maximum retention period is 18 hours.
    • Rule 2: If one of the following conditions is met, ApsaraDB RDS deletes earlier binary log files until the condition is not met.
      • The storage usage that is calculated by using the following formula exceeds the threshold that is specified by the Max Storage Usage parameter: Storage usage = (Size of binary log files/Size of storage capacity) × 100%. The default threshold is 30%.
      • The number of binary log files exceeds the maximum number that is specified by the Retained Files parameter. By default, the maximum number is 60.
      • The storage usage exceeds 80% or the amount of available storage is less than 5 GB. Make sure that you set the Protect Available Storage parameter to Enable.

To manually delete the binary log files of an RDS instance, perform the following steps:

  1. Visit the RDS instance list, select a region above, and click the target instance ID.
  2. In the left-side navigation pane, click Backup and Restoration.
  3. Click Upload Binlogs. Then, click OK.

    If you perform this operation, all binary log files except the most recent two binary log files are deleted. Examples:

    • If the mysql-bin.000192, mysql-bin.000193, and mysql-bin.000194 binary log files are stored in the RDS instance, only the mysql-bin.000192 binary log file is deleted upon this operation.
    • If only two binary log files are stored in the RDS instance, no binary log files are deleted upon this operation.
    Note
    • ApsaraDB RDS deletes binary log files at a latency.
    • This operation is not supported for RDS instances that run RDS Basic Edition.
    • If binary log files cannot be deleted and the following warning is displayed on the Error Logs tab of the Logs page, the database client may encounter errors or a change tracking task is in progress. Before you can delete the binary log files, you must stop the task.
      [Warning] file /home/mysql/data3001/mysql/mysql-bin.069435 was not purged because it was being readby thread number 17126285
    • If you use the Upload Binlogs feature, the RDS instance uploads binary log files to the specified Object Storage Service (OSS) bucket. The retention period of binary log files that are stored as objects in the OSS bucket is the same as the log backup retention period that you specify on the RDS instance.
  4. Log on to the RDS instance and run the show binary logs; command to view the binary log files of the RDS instance. For more information, see Use DMS to log on to an ApsaraDB RDS for MySQL instance.
  5. View the size of binary log files on the Monitoring and Alerts page.

Related operations

Operation Description
PurgeDBInstanceLog Deletes the binary log files of an ApsaraDB RDS instance.

FAQ

  • Why is the size of binary log files on the primary RDS instance different from the size of binary log files on the secondary RDS instance in my database system?
    By default, the size of binary log files on the primary RDS instance is the same as the size of binary log files on the secondary RDS instance. The two sizes may be different due to the following reasons:
    • The primary RDS instance replicates data to the secondary RDS instance at a latency, the Binlog dump thread dumps the binary log files at a latency, or Data Transmission Service (DTS) is migrating data from or to the primary RDS instance.
    • The secondary RDS instance is reading and applying log records.
  • Why does ApsaraDB RDS delete a binary log file of my RDS instance immediately after the binary log file is generated?

    The storage usage of the RDS instance may have reached 80%, or the amount of available storage on the RDS instance is less than 5 GB. At this time, if you set the Protect Available Storage parameter in the Local Log File Settings dialog box to Enable, all binary log files are deleted immediately after they are generated. We recommend that you manually increase the storage capacity of the RDS instance or enable the automatic storage expansion feature for the RDS instance. This way, the RDS instance is not locked even if the storage usage reaches 80% or the amount of available storage is less than 5 GB. For more information, see Change the specifications of an ApsaraDB RDS for MySQL instance or Configure automatic storage expansion for an ApsaraDB RDS for MySQL instance.