pg_receivexlog pg_receivewal - ghdrako/doc_snipets GitHub Wiki

One recommended way to set WAL backup is using the built-in PostgreSQL tool called pg_receivexlog (which is pg_receivewal from PostgreSQL 10). It is very easier to set up than your archive_command. You can run it on your archive server, but do not archive to the same machine that your database is on. If you lose the primary machine, you will lose both your backups and your primaries.

If you run pg_receivexlog, it connects to PostgreSQL over the replication protocol. It’s basically a PostgreSQL replication standby without PostgreSQL, and it regenerates the log archive based on the replication data on your archive server. It gives you a more granular recovery. With an archive command, data gets sent inblocks of 16 megabytes; but with pg_receivexlog, they get sent in chunks, as it uses streaming protocol to stream the WALs. Hence, it doesn’t need to wait for the WAL segment to get completed. It is safe against server restarts. If your server reboots in the middle of running your archived command—like your cp command is running but it didn’t finish and then the server rebooted—then data loss or data corruption can happen. pg_receivexlog can take care of that, as it can follow timeline switches on the master. Always use pg_receivexlog together with a replication slot so that no xlog will be removed before they back up. The replication slot ensures that no WAL is removed from primary until they have been received by all standbys. More information is available at: www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-SLOTS.

pg_receivewal -D /log/archive -h master -S backup
  • -S is for replication slot.