Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

cloud sql mysql database instance binlog is keep increasing

Hi in my database instance the size of binlog is getting  bigger and bigger it is around 482 gb , I need solution to reduce it also why is it keep increasing why google is not flushing it after 1 week.image_2023_07_07T05_46_57_430Z.png

0 5 3,320
5 REPLIES 5

CloudSQL for MySQL should automatically purge binary logs after 7 days by default. However, there are a few reasons why this might not be happening:

  1. Custom Configuration: If the binlog_expire_logs_seconds flag has been set to a value greater than 604800 (7 days in seconds), then binary logs will be kept for longer than 7 days. Check your Cloud SQL instance's flags to see if this is the case.

  2. Active Connections: If there are active connections that are still reading from a binary log file, that file cannot be purged. This is often the case with replication, where a replica might be lagging behind and still reading from an old binary log file. In this case, you would need to ensure that all replicas have read the binary log file before it can be purged.

Now I know the reasons for increase in size of binary logs , Is there any way I can remove or reduce the size the binary logs safely from the database instance.

Yes, you can safely reduce the size of binary logs in your Google Cloud SQL instance by following these steps:

  1. Check Replication Status: If you have any replica databases, ensure they are all caught up with the master database. If a replica is lagging behind, it might still be reading from an old binary log file, preventing that file from being purged.

  2. Adjust Binary Log Expiration: To prevent binary logs from consuming too much disk space in the future, you can adjust the binary log expiration period. In Google Cloud SQL, you can do this by setting the binlog_expire_logs_seconds flag to a lower value. For example, to keep binary logs for 7 days, you can set binlog_expire_logs_seconds to 604800 (which is 7 days in seconds).

Remember, it's important to monitor your disk usage regularly to ensure that you have enough space for your database operations. If your disk usage is consistently high, you might need to consider increasing your disk size or optimizing your database to reduce disk usage.

Hi does long mysql procedures which sort all data increase bin log size or increase database replica lag.

Yes, long MySQL procedures that make extensive changes to the data can increase the binary log size and database replica lag. However, simply sorting data without making changes won't directly increase the binary log size. MySQL logs all changes to the database in the binary log to maintain a consistent view of the data for replicas. When a procedure makes many changes, it can generate a large number of binary log events, leading to an increased binary log size and potential replica lag.

To mitigate the impact of long MySQL procedures:

  • Avoid running extensive data-modifying procedures during peak business hours.
  • Use batch processes to run these procedures outside of peak times.
  • Consider using temporary tables when appropriate, as changes to temporary tables are not logged in the binary log. However, ensure subsequent operations using the temporary table that modify permanent tables are optimized.
  • Monitor the binary log size and database replica lag regularly. If issues arise, consider adjusting the binary log retention settings or adding more replicas to distribute the replication load.