mysql 从库落后主库太多优化

有时候为了避免master.info和中继日志崩溃,在容忍额外的fsync()带来的开销,推荐设置
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1

当然,如果备库跟主库延迟特别大,备库的io线程谢了很多中继日志,通过relay_log_purge设置,sql线程重放完一个中继日志中的事件后会尽快将删除。
极端情况下,需要设置relay_log_space_limit,这样如果中继日志的大小超过这个值,I/O线程将停止,等待sql线程释放磁盘空间。

sync_master_info:每间隔多少事务刷新master.info,如果是table(innodb)设置无效,每个事务都会更新
    The effects of this variable on a replication slave depend on whether the slave's master_info_repository is set to FILE or TABLE
sync_relay_log:默认为10000,即每10000次sync_relay_log事件会刷新到磁盘。为0则表示不刷新,交由OS的cache控制
    If the value of this variable is greater than 0, the MySQL server synchronizes its relay log to disk (using fdatasync()) after every sync_relay_log events are written to the relay log. Setting this variable takes effect for all replication channels immediately, including running channels
sync_relay_log_info:每间隔多少事务刷新relay-log.info,如果是table(innodb)设置无效,每个事务都会更新
master_info_repository:记录主库binlog的信息,可以设置FILE(master.info)或者TABLE(mysql.slave_master_info)
relay_log_info_repository:记录备库relaylog的信息,可以设置FILE(relay-log.info)或者TABLE(mysql.slave_relay_log_info)

为了快速让从库同步主库最新数据,可临时修改以下配置:

innodb_flush_log_at_trx_commit = 0

sync_binlog = 0

sync_master_info = 2000
sync_relay_log = 2000
sync_relay_log_info = 2000

posted @ 2018-07-06 11:58  lvelvis  阅读(1350)  评论(0编辑  收藏  举报
#####