Re: Warm standby problems

From: "David F(dot) Skoll" <dfs(at)roaringpenguin(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Warm standby problems
Date: 2009-10-27 11:32:29
Message-ID: 4AE6DA4D.2060509@roaringpenguin.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Tom Lane wrote:

> What about the other direction: the script invoked by the archive
> returns "done" before the bits have all been shipped?

Do you mean the wal_archive_command? It waits for scp to finish.
It's written in Perl; here is the relevant part.

Regards,

David.

[Stuff deleted...]

my $remote_user = $failover->get_setting('backup_ssh_user');
my $remote_host = $failover->get_setting('backup_db_host');
my $remote_directory = $failover->get_setting('backup_wal_dir');
my $postgres_user = $failover->get_setting('pg_userid') || 'postgres';

my $pid = open(CHILD, '-|');
my $wal_filename_only;
(undef, undef, $wal_filename_only) = File::Spec->splitpath( $wal_file );

if( $pid ) { # Parent

while(<CHILD>) {
chomp;
canit_log( "Output from scp: $_" );
}

# This should wait for scp to finish
my $rc = close CHILD;
my $errno = $!;
my $child_error = $?;
alarm(0);

if( ! $rc ) {
if( $errno ) {
canit_warning("Error closing pipe from scp: $errno");
exit EXIT_FAILURE;
} elsif ($child_error & 127) {
canit_warning("scp died with signal " . ($child_error & 127));
exit EXIT_FAILURE;
} else {
canit_warning("scp exited with non-zero exit code " . ($child_error >> 8));
exit EXIT_FAILURE;
}
}

my $exit_status = EXIT_OK;
if (system('ssh', "$remote_user\(at)$remote_host", "chown $postgres_user $remote_directory/$wal_filename_only.NEW") != 0) {
canit_warning("ssh command to chown remote file failed: $?");
$exit_status = EXIT_FAILURE;
}

if (system('ssh', "$remote_user\(at)$remote_host", "mv -f $remote_directory/$wal_filename_only.NEW $remote_directory/$wal_filename_only") != 0) {
canit_warning("ssh command to rename remote file failed: $?");
$exit_status = EXIT_FAILURE;
}

if ($exit_status == EXIT_OK) {
canit_log("Successully archived WAL file $wal_filename_only on $remote_host");
}

exit $exit_status;
}

# In the child:
# Make sure we capture STDERR
open(STDERR, '>&STDOUT');

# In new scope to suppress warning about code after an exec - see
# 'perldoc exec' for details
{
no warnings 'exec';
exec 'scp', '-q', $wal_file, "$remote_user\(at)$remote_host:$remote_directory/$wal_filename_only.NEW";
}

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message sateesh kumar 2009-10-27 11:34:24 how to intract between databases please let me know
Previous Message TiTo® 2009-10-27 10:50:54 Re: Permissions to schema