Mysql – How much RAM should you allocate a MySQL replication slave

memoryMySQLreplication

Our MySQL master is allocated 24GB of RAM (innodb_buffer_pool_size = 24GB), but was curious if there was some standard amount to allocate to a replication slave?

Right now the slave is just used to take dumps without locking tables on master, and in theory be used as an emergency master if something happens (hasn't come up in the last 18mo). If master fails I could always quickly allocate the slave 24GB, but how much does a slave really need to just sit there replicating?

Best Answer

The amount of memory should be the same, the config should be the same (except config that pertain to Master / Slave only).

Reason is when you fail over, you don't want to spend time trying to find out what value should be there or not. I would even create 2 my.cnf files: my.cnf and my_failover.cnf (prepare my.cnf on Slave in case master fails. File can contain binlog=1 (turn on bin log).

All you should need to do is:

  • mv my.cnf mybk.cnf, my my_failover.cnf my.cnf
  • Restart Mysql.

Then your slave will start login.

Regarding caching queries, well, all Select statement running on Master won't replicate to Slave. If your Master is 80% Select / 20% write, it should not be a problem.

If you want to cache your Select from Master, turn on Slow Query log for query > 1 sec then apply that to Slave. You could do that once a day (in morning).

Chances are, soon you'll be using your slave for reporting.

You could also use Percona Playback.