Re: Warm standby problems

Поиск
Список
Период
Сортировка
От David F. Skoll
Тема Re: Warm standby problems
Дата
Msg-id 4AE6DA4D.2060509@roaringpenguin.com
обсуждение исходный текст
Ответ на Re: Warm standby problems  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Warm standby problems: Followup  ("David F. Skoll" <dfs@roaringpenguin.com>)
Список 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\@$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\@$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\@$remote_host:$remote_directory/$wal_filename_only.NEW";
}

В списке pgsql-admin по дате отправления:

Предыдущее
От: TiTo®
Дата:
Сообщение: Re: Permissions to schema
Следующее
От: sateesh kumar
Дата:
Сообщение: how to intract between databases please let me know