Mysql – Maximum overall size of MariaDB binary logs

binlogmariadbMySQL

I am looking for a way to prevent MariaDB binary logs from taking a huge size when they grow faster than usual.

  • variable max_binlog_size set the maximum size of ONE binary logfile.
  • variable expire_log_days set the number of days after which the binary logs are removed.

But is there a way to set a "maximum overall size" of ALL binary log files? or, maybe simpler, a maximum number of binary log files, which would overload expire_log_days retention…

Best Answer

max_binlog_size

With regards to max_binlog_size, what you are asking is not possible. Why ?

On May 05, 2017, I answered the question MySQL - Binary Log File size growing more than the maximum limit. I mentioned the following from the MySQL Documentation on max_binlog_size:

A transaction is written in one chunk to the binary log, so it is never split between several binary logs. Therefore, if you have big transactions, you might see binary log files larger than max_binlog_size.

That fact that your binary logs are bigger than max_binlog_size just indicates that you are writing too many changes per single transaction.

expire_logs_days

With regards to expire_logs_days, the granularity is in days. There is nothing you can do with that.

If you wish to squeeze the number of binlogs down, you may have do one of two things:

SUGGESTION #1 : Scan in the binlog index file, find the last 10 binlogs, get the first binlog of those 10, and run something like:

PURGE BINARY LOGS TO 'whatever-binlog.002316';

SUGGESTION #2 : Write a cronjob that will keep the last 18 hours of binary logs:

PURGE BINARY LOGS BEFORE (NOW() - INTERVAL 18 HOUR);

GIVE IT A TRY !!!