my $RETRYSLEEP = delete $bcargs->{retrysleep} || 0;
my $NOTIMER = delete $bcargs->{notimer} || 0;
-my $NO_PG_LISTENER = 1;
-
my $DBCONN = "User: $bcargs->{dbuser} Database: $bcargs->{dbname}";
$bcargs->{dbhost} and length $bcargs->{dbhost} and $DBCONN .= " Host: $bcargs->{dbhost}";
$bcargs->{dbport} and length $bcargs->{dbport} and $DBCONN .= " Port: $bcargs->{dbport}";
my $gotall = 0;
my @allvars;
SYNCMATCH: for my $sync (@nouns) {
+
if ($sync =~ /^\d+$/) {
$adverb = $sync;
next SYNCMATCH;
next SYNCMATCH;
}
next if $sync eq 'sync';
+
if (! exists $syncs->{$sync}) {
- die qq{Sync "$sync" does not appear to exist\n};
+ ## Be nice and print a list of active syncs
+ my @goodsyncs;
+ for my $s (sort keys %$syncs) {
+ push @goodsyncs => $s if $syncs->{$s}{status} eq 'active';
+ }
+ my $msg = qq{Sync "$sync" does not appear to exist\n};
+ if (@goodsyncs) {
+ $msg .= "Active syncs:\n";
+ $msg .= join "\n" => @goodsyncs;
+ }
+ die "$msg\n";
}
push @syncs, $sync;
}
if ($maj < 8 or (8 == $maj and $min < 1)) {
die "Sorry, Bucardo requires Postgres version 8.1 or higher. This is only $maj.$min\n";
}
- $NO_PG_LISTENER = 1 if $maj >= 9;
}
sub help {
exit 1;
}
- ## Is someone listening for this sync? (We assume its the MCP) Note that we
- ## can't find this out in pgsql 9.0 or greater, because there's no longer a
- ## way to know what's being listened for.
- my $sthl = $NO_PG_LISTENER ? undef : $dbh->prepare('SELECT 1 FROM pg_listener WHERE relname = ?');
+ ## Before kicking, we want to make sure the sync is active and being listened for
my ($exitstatus, $retries, $do_retry) = (0,0,0);
SYNC: for my $sync (@syncs) {
my $relname = "bucardo_kick_sync_$sync";
- if (defined $sthl) {
- ## If nobody is listening, our kick is not going to be very effective!
- $count = $sthl->execute($relname);
- $sthl->finish();
- if ($count < 1) {
- warn qq{Cannot kick sync "$sync" - are you sure it is active?\n};
- die "Available syncs: " . Dumper($dbh->selectall_arrayref('SELECT * FROM pg_listening_channels()'));
- next;
- }
- }
-
$dbh->do(qq{NOTIFY "bucardo_kick_sync_$sync"});
my $done = "bucardo_syncdone_$sync";
my $killed = "bucardo_synckill_$sync";
}
## Make sure none of the syncs are currently running
- if ($NO_PG_LISTENER) {
- ## XXX Is there anything we can do to check that the sync is active?
- 0;
- }
- else {
- $SQL = q{SELECT 1 FROM pg_catalog.pg_listener WHERE relname = ?};
- for my $name (@nouns) {
- my $dname = "bucardo_deactivate_sync_$name";
- $sth = $dbh->prepare($SQL);
- $count = $sth->execute($dname);
- $sth->finish();
- if (1 == $count) {
- die qq{Cannot remove active sync "$name": please deactivate it first\n};
- }
- }
- }
+ ## XXX Is there anything we can do to check that the sync is active?
$SQL = 'DELETE FROM bucardo.sync WHERE name = ?';
$sth = $dbh->prepare($SQL);
if ($maj < 8 or (8 == $maj and $min < 1)) {
die "Sorry, Bucardo requires Postgres version 8.1 or higher. This is only $maj.$min\n";
}
- $maj >= 9 and $NO_PG_LISTENER = 1;
$COM = "$PSQL -AX -qt -f $schema_file 2>&1";
print "COM=$COM\n";