I've been playing at last with the new Streaming Replication and Hot Standby stuff. While it's possible to run these without also archiving log files, I gathered from
Heikki's talk at pgCon that it's not necessarily a good idea. So if you do use archive logging, how do you make sure the archive doesn't just keep growing?
With older style PITR warm standby setups, pg_standby used to take care of that for us, but we can't use that with Hot Standby. Instead, there is a setting in recovery.conf that lets us call a command to do the cleanup ourselves. Slightly annoyingly, there isn't an example in the docs. Here is what I came up with:
#!/usr/bin/perl
use strict;
use File::Basename;
my ($dir, $num) = @ARGV;
my $log;
open($log,">>/home/andrew/restart_log") || die $!;
my $date = localtime();
print $log "$date: restart_point.pl\n";
foreach my $file (glob("$dir/*"))
{
next unless -f $file;
my $name = basename($file);
next unless $name =~ /^[0-9A-Z]{24}$/;
if ( $name lt $num )
{
print $log "deleting $file\n";
unlink $file;
}
}
close $log;
and the corresponding entry in the recovery.conf is:
restartpoint_command = '/home/andrew/restart_point.pl /home/andrew/pg-walspool %r'
It seems to do the right thing.