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
##主库归档日志可以放到nfs
archive_mode = on
archive_command = ‘cp %p /path_to/archive/%f’

 

on slave

从库的recovery.conf文件
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_command setting

方式2

增加wal_keep_segments = 5000(可以是任意大数)
增加segment的大小
重新配置流复制

posted @ 2020-01-15 15:53  slnngk  阅读(775)  评论(0编辑  收藏  举报