PG主从流复制WAL被覆盖解决方式

PostgreSQL的流复制的原理是通过传递主机(master)上的wal日志信息到备机(slave)然后恢复,这中间就有一个潜在的问题,如果主机端比较忙,wal日志被覆盖了,而从机可能因为网络或者其他原因没有接收到该日志,就会造成主从不一致

requested WAL segment 0000000100000001000000A has already been removed

方式1:

借用老外的办法,国内的基本都是照抄:
archive_mode enables WAL archiving which can be used to recover files older than wal_keep_segments provides. The slave servers simply need a method to retrieve the WAL segments. NFS is the simplest method, but anything from scp to http to tapes will work so long as it can be scripted.

on master

archive_mode = on
archive_command = ‘cp %p /path_to/archive/%f’

on slave

restore_command = ‘cp /path_to/archive/%f “%p”’

When the slave can’t pull the WAL segment directly from the master, it will attempt to use the restore_command to load it. You can configure the slave to automatically remove segments using the archive_cleanup_commandsetting

方式2

增加wal_keep_segments = 5000(可以是任意大数)
增加segment的大小
重新配置流复制。教程网上到处都有

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章