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的大小
重新配置流複製。教程網上到處都有