5

I have a MySQL server with slave replication on another host. Today I stumbled across the high disk usage of the slave host and invastigated what takes up all the space. As it turns out this space is occupied by the slaves relay logs.

I tried to turn the expire_logs_days variable down and restarted the MySQL daemon but the reported disk space stays the same. I could't really find anything exept that FLUSH LOGS should clear old logs. I tried that with no result.

Is there any way I can reduce the disk space that the relay logs take?

3
  • Is the slave up to date with the master? It should delete relay logs when it is so if it isn't deleting them, I'd suspect it's not up to date.
    – Ladadadada
    Jun 26, 2013 at 8:36
  • It seems to be behind. So I'll wait until it's up to date and see if it deleted the old files.
    – Izzy
    Jun 26, 2013 at 8:54
  • Run 'mysqladmin refresh' daily in a cron job. Description: "Flush all tables and close and open log files." If the replication is caught up, it will close the relay log file, create and use a new one, and delete the old one.
    – Todd Lyons
    Jun 26, 2013 at 17:40

2 Answers 2

6

The expire_logs_days setting controls binary logging, not relay logging.

Normally, the relay logs are purged when the slave has finished applying the data from them. This can be changed with relay-log-purge, but it's default is 1.

If your slave is simply behind, it will continue to accumulate relay logs by design. You might want to consider setting relay-log-space-limit to prevent out of disk space problems. This setting provides a disk space limit for the IO thread to use for storing relay logs.

1

Make sure you haven't set relay_log_purge=0 in your configuration. I had set this option while troubleshooting a replication issue and forgot to remove it. Later we found the logs disk was filling up due to the relay logs not being purged after being applied.

You can check and set the state of this variable dynamically like this:

> SELECT @@global.relay_log_purge;
+--------------------------+
| @@global.relay_log_purge |
+--------------------------+
|                        0 |
+--------------------------+

> SET @@global.relay_log_purge = 1;
Query OK, 0 rows affected (0.04 sec)

> SELECT @@global.relay_log_purge;
+--------------------------+
| @@global.relay_log_purge |
+--------------------------+
|                        1 |
+--------------------------+
1
  • You could've just edited the existing 7 year old accepted answer instead of basically duplicating it x.x
    – Izzy
    Jul 6, 2020 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.