I just encountered the problem described in the title. On a server I don’t have enough free space to create a backup while the replica is catching up, because the relay logs eat all the available free space as the IO thread works faster than the SQL thread in the replication.
What to do? First, we need to get rid of the current relay logs, and then limit how many it creates in the future. The relay logs are not meant for manual deletion so we stop the replica, purge the relay logs, set back the replica to the previous position and then restart the mysqld with the relay_log_space_limit variable set up.
mysql> STOP SLAVE; mysql> PAGER egrep "Relay_Master_Log_File|Exec_Master_Log_Pos" mysql> SHOW SLAVE STATUS\G mysql> RESET SLAVE ALL; mysql> CHANGE MASTER TO ... mysql> START SLAVE; mysql> ^d bash> echo "relay-log-space-limit = 10737418240" >>/etc/mysql/my.cnf #10G bash> systemctl mysql restart
As Jean-François Gagné pointed out (rightly), this only applies in a really simple case when there is no GTID configured, no parallel replication exists, the slave is not delayed, no SSL, etc.etc.
