I'm running postgresql 9.3. I've currently got WAL archiving configured, but I'm doubting it's utility based on my configuration. On the master, I've got archive_command set to
rsync -az –ignore-existing %p postgres@slave_replica:/wal_archive
and on the slave replica, I've got restore_command set to
cp /wal_archive/%f %p || exit 0
If the slave server goes offline, it won't be able to receive the WAL files, and then when it comes back up, won't have what it needs.
Should I instead effectively reverse those two commands: archive the WALs locally on the master, and have slave replica rsync them from the master server? Or should I have the master archive the WALs both to a local directory and rsync them to the slave?
Best Answer
If the slave server is offline, the
rsync
in thearchive_command
should fail (exit with a non-zero exit value), which means the master will keep retrying it until it succeeds. It will not remove a pg_xlog file until it is successfully archived. So it will still be there when the slave comes back on online.Also, the
|| exit 0
at the end of your restore command is just wrong.PostgreSQL
will ask for files which do not exist, and has to be told they don't exist (by returning a non-zero exit code)