I have two MySQL (MariaDB actually) servers, a master and a slave with standard replication. Two times already in less than a month I've had my slave become unusable.
This is what I experienced:
- Notice a drop in query per second on the slave with my monitoring tool
- Connect to the server with the mysql client, run
SHOW SLAVE STATUS \G
- Notice everything looks normal (Waiting for master to send event, seconds behind master = 0, etc)
- Try and stop the replication with
STOP SLAVE
STOP SLAVE
hangs- Impossible to connect to the server with a client
- Execute
SHOW SLAVE STATUS \G
on another already connected client, and it hangs too.
After that, I saw the MySQL process using CPU, and I saw a lot of disk writes with iotop, so I let it do its stuff for a while.
After 15 minutes I killed -9 the MySQL process because I got frustrated. I then restart MySQL, and I can connect and run queries, good.
I execute SHOW SLAVE STATUS \G
which now works, and it looks normal: seconds behind master = 0, waiting for events. Then I go on the master and execute CREATE DATABASE foobar
to see if the replication works, and it doesn't.
Again, at that point I see a lot of disk writes so I assume the replication is catching up.
Two hours later, I finally decide to check SHOW PROCESSLIST
and all I see being executed is a OPTIMIZE TABLE table1 ...
and then I remember that I had that exact same problem last time.
I kill the process with that query, then I reexecute SHOW PROCESSLIST
and sure enough it's catching up with the master. SHOW SLAVE STAUTS \G
reported 15k seconds behind master, which was coherent.
Anyway, after that wall of text, my questions:
- why does a OPTIMIZE query block the replication catching up ?
- can I prevent those OPTIMIZE queries ? I didn't put any cron to do that, and as far as I can see, nothing in /etc/cron.{d,daily,hourly,weekly} does this.
Thanks.
STOP SLAVE
during a long-running operation,STOP SLAVE
will block and subsequentSHOW SLAVE STATUS
will also block. That behavior is confusing but normal -- in the interest of data integrity,STOP SLAVE
does not stop the slave until the current replication event group has finished executing.