Postgresql – How to update the database generated pg_basebackup through WAL files

backuppostgresqlpostgresql-9.3restorewrite-ahead-logging

Following on from this post

I have a backup generated by pg_basebackup regularly, I would update it through the WAL files.

What is the best way to do it?

Best Answer

See the documentation on point-in-time recovery and WAL archiving for how to manage this.

Short version:

  • Set archive_mode = on in master
  • Set an archive_command in master that stores the WAL archives in a location accessible to the replica
  • Create the replica from a pg_basebackup
  • Create a recovery.conf on the replica that sets a restore_command to fetch the archived WAL. You may also want to set a recovery_target_time if you wish to stop replay at a certain point.
  • Start the replica and let it replay WAL

You may find tools like pgbarman useful as well.