How to do it...

The first thing we need to do is secure the WAL stream. Follow these steps to build a semi-permanent copy of archived WAL data in the /db/wal_archive directory:

  1. On the primary node, modify the postgresql.conf file to include the following setting:
        archive_command = 'cp -an %p > /db/wal_archive/%f' 
  1. Create the /db/wal_archive directory as a root-capable user using the following commands:
        sudo mkdir -p -m 0700 /db/wal_archive
        sudo chown -R postgres /db/wal_archive
  1. Reload the PostgreSQL service using the following command:
        pg_ctl -D /path/to/database reload
  1. As a root-capable user, create a script named del_archives in the /etc/cron.daily directory and fill it with this content as a single line:
 find /db/wal_archive ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.