Re: pg_basebackup on slave running for a long time

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: pg_basebackup on slave running for a long time
Date: 2016-11-22 16:51:34
Message-ID: b8f833ec-7cd8-4a75-6d82-25eafdac585e@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/22/2016 3:41 AM, Subhankar Chattopadhyay wrote:
> John,
>
> Can you explain the Wal Archive procedure, how it can be setup so that
> the slave never goes out of sync, even if master deletes the WAL
> files?

The WAL archive will typically be a separate file server that both the
master and slave can reach... it could be accessed via NFS or via scp
or whatever is appropriate for your environment. The master is
configured with an archive command (cp in the case of nfs, or scp for
ssh/scp, or whatever) to copy WAL segments to the archive. The slave
is setup with an recovery command (cp, scp, etc) to fetch from this same
archive.

The archive will continue grow without limit if you don't do some
cleanup on it. one strategy is to periodically (weekly? monthly?) do
a base backup of the master (possibly by using rsync or another file
copy method, rather than pg_basebackup), and keep 2 of these full
backups, and all wal archives since the beginning of the oldest one.
with this backup + archive, you can initialize a new slave without
bothering the master (rsync or scp or cp the latest backup, then let the
slave recover from the wal archive).

this backup+archive will also let you do point-in-time-recovery (aka
PITR). say something catastrophic happens and the data in the master
is bad after some point in time (maybe a jr admin accidentally clobbers
key data, but the app kept running). you can restore the last good
base backup, and recover up to but not including the point in time of
the transaction that clobbered your data.

--
john r pierce, recycling bits in santa cruz

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Israel Brewster 2016-11-22 16:57:12 Re: Streaming replication failover/failback
Previous Message John R Pierce 2016-11-22 16:42:43 Re: pg_basebackup on slave running for a long time