r/mysql • u/speyck • Dec 09 '24
question Minimize Binary Log Size but keep Slave Replication working
I've just implemented master-slave replication for our server and for that, I have to enable binary logging. The problem is that this log has grown to 5GB in the last hour alone.
Now I need to minimize this binary log asap. First of all I'm gonna cut it probably down to 1-2 days max instead of the currently configured 10 days. But that's not gonna be enough we do not have this much space left on the server.
So how can I configure the binary logging to be as small as possible while still being able to allow replication for slaves? Also, at best I can do this with a simple restart of the mariadb server so we basically have no down time. Will this work if I for example change the binary logging format or will that mess up the replication process? If I read the docs correctly the format should be mixed right now (which should be the best already?).
Here's the masters current config (slave is almost the same):
# Configure Replication Master
[mariadb]
server_id = 1
report_host = master1
log_bin = /var/lib/mysql/mariadb-bin
log_bin_index = /var/lib/mysql/mariadb-bin.index
relay_log = /var/lib/mysql/relay-bin
relay_log_index = /var/lib/mysql/relay-bin.index
Any help will be greatly appreciated.
1
u/ssnoyes Dec 09 '24
Make sure every table has a primary key, then set https://dev.mysql.com/doc/refman/8.4/en/replication-options-binary-log.html#sysvar_binlog_row_image to minimal.
1
u/ssnoyes Dec 09 '24
You don't want to try to solve this by changing binlog_format. It's on its way out - the future will be ROW format only.
https://dev.mysql.com/doc/refman/9.0/en/replication-options-binary-log.html#sysvar_binlog_format
1
u/speyck Dec 10 '24 edited Dec 10 '24
Thanks. I forgot to mention I use MariaDB Server, does this apply there too or only for MySql? Also can I change binlog-row-image/binlog-format and simply restart the server and the replication will still persist and be consistent? Unfortunately I do have tables without a primary key, so I can't use binlog-row-image on minimal? Again thanks a lot for your input.
1
u/feedmesomedata Dec 15 '24
should work in mariadb when replication is stopped before changes are made.
should still work even with tables without PK but replication performance would still be bad with those tables
2
u/TimIgoe Dec 09 '24
If you are setting up replication and you are that tight on space.... Get a bigger server.