wadesworld
wadesworld

Reputation: 13733

pg_archivecleanup and streaming replication

Using postgres 9.3.

I'm a bit confused on the proper usage of pg_archivecleanup.

I'm using both streaming replication and backup with continuous archiving for PITR recovery.

I don't think I can configure pg_archivecleanup in recovery.conf on the standby as it wouldn't achieve anything. The master is not archiving to a location accessible to the standby. The master is archiving to a location on its local disk, and then those archives and the associated backup are being rsync'd to a large backup disk.

So, it seems the solution would be to run pg_archivecleanup in "standalone" mode on the master, such as:

/usr/lib/postgresql/9.3/bin/pg_archivecleanup -d /archive 0000000100000010000000F0.00000028.backup

So, I'd do a cron job that would run the pg_archivecleanup command for any .backup files which are older than the latest one, and then delete those backup files, leaving only the latest one.

Is my understanding and plan correct?

Upvotes: 2

Views: 1718

Answers (1)

Egor Rogov
Egor Rogov

Reputation: 5388

If you want to retain only WAL segments after the latest base backup, you simply run pg_archivecleanup in standalone mode for the latest .backup file (not for those older than the latest).

But do you really want to have only one available backup? First of all, you won't be able to restore to the point before the last backup. Second, it makes sense to have some backups just in case (corruptions, etc).

And it seems strange to archive segments to local disk and then rsync them elsewhere. Why not putting your rsync (and then sync to flush OS buffers to disk) into archive_command? This ensures that the segment won't be removed from pg_xlog before it reaches the destination.

Upvotes: 2

Related Questions