Commit 8e93a516 authored by Peter Eisentraut's avatar Peter Eisentraut

Don't propagate PGAPPNAME through pg_ctl in tests

When libpq is loaded in the server (for instance, by
libpqwalreceiver), it may use libpq environment variables set in the
postmaster environment for connection parameter defaults.  This has
some confusing effects in our test suites.  For example, the TAP test
infrastructure sets PGAPPNAME to allow identifying clients in the
server log.  But this environment variable is also inherited by
temporary servers started with pg_ctl and is then in turn used by
libpqwalreceiver as the application_name for connecting to remote
servers where it then shows up in pg_stat_replication and is relevant
for things like synchronous_standby_names.  Replication already has a
suitable default for application_name, and overriding that
accidentally then requires the individual test cases to re-override
that, which is all very confusing and unnecessary.

To fix, unset PGAPPNAME temporarily before running pg_ctl start or
restart in the tests.

More comprehensive approaches like unsetting all environment variables
in pg_ctl were considered but might be too complicated to achieve
portably.

The now unnecessary re-overriding of application_name by test cases is
also removed.
Reviewed-by: default avatarNoah Misch <noah@leadboat.com>
Discussion: https://www.postgresql.org/message-id/flat/33383613-690e-6f1b-d5ba-4957ff40f6ce@2ndquadrant.com
parent c21d6033
...@@ -160,7 +160,7 @@ sub create_standby ...@@ -160,7 +160,7 @@ sub create_standby
$node_standby->append_conf( $node_standby->append_conf(
"postgresql.conf", qq( "postgresql.conf", qq(
primary_conninfo='$connstr_master application_name=rewind_standby' primary_conninfo='$connstr_master'
)); ));
$node_standby->set_standby_mode(); $node_standby->set_standby_mode();
...@@ -180,7 +180,7 @@ sub promote_standby ...@@ -180,7 +180,7 @@ sub promote_standby
# up standby # up standby
# Wait for the standby to receive and write all WAL. # Wait for the standby to receive and write all WAL.
$node_master->wait_for_catchup('rewind_standby', 'write'); $node_master->wait_for_catchup($node_standby, 'write');
# Now promote standby and insert some new data on master, this will put # Now promote standby and insert some new data on master, this will put
# the master out-of-sync with the standby. # the master out-of-sync with the standby.
......
...@@ -698,12 +698,24 @@ sub start ...@@ -698,12 +698,24 @@ sub start
my $port = $self->port; my $port = $self->port;
my $pgdata = $self->data_dir; my $pgdata = $self->data_dir;
my $name = $self->name; my $name = $self->name;
my $ret;
BAIL_OUT("node \"$name\" is already running") if defined $self->{_pid}; BAIL_OUT("node \"$name\" is already running") if defined $self->{_pid};
print("### Starting node \"$name\"\n"); print("### Starting node \"$name\"\n");
# Note: We set the cluster_name here, not in postgresql.conf (in
# sub init) so that it does not get copied to standbys. {
my $ret = TestLib::system_log('pg_ctl', '-D', $self->data_dir, '-l', # Temporarily unset PGAPPNAME so that the server doesn't
$self->logfile, '-o', "--cluster-name=$name", 'start'); # inherit it. Otherwise this could affect libpqwalreceiver
# connections in confusing ways.
local %ENV = %ENV;
delete $ENV{PGAPPNAME};
# Note: We set the cluster_name here, not in postgresql.conf (in
# sub init) so that it does not get copied to standbys.
$ret = TestLib::system_log('pg_ctl', '-D', $self->data_dir, '-l',
$self->logfile, '-o', "--cluster-name=$name", 'start');
}
if ($ret != 0) if ($ret != 0)
{ {
...@@ -776,9 +788,17 @@ sub restart ...@@ -776,9 +788,17 @@ sub restart
my $pgdata = $self->data_dir; my $pgdata = $self->data_dir;
my $logfile = $self->logfile; my $logfile = $self->logfile;
my $name = $self->name; my $name = $self->name;
print "### Restarting node \"$name\"\n"; print "### Restarting node \"$name\"\n";
TestLib::system_or_bail('pg_ctl', '-D', $pgdata, '-l', $logfile,
'restart'); {
local %ENV = %ENV;
delete $ENV{PGAPPNAME};
TestLib::system_or_bail('pg_ctl', '-D', $pgdata, '-l', $logfile,
'restart');
}
$self->_update_pid(1); $self->_update_pid(1);
return; return;
} }
...@@ -835,7 +855,7 @@ sub enable_streaming ...@@ -835,7 +855,7 @@ sub enable_streaming
print "### Enabling streaming replication for node \"$name\"\n"; print "### Enabling streaming replication for node \"$name\"\n";
$self->append_conf( $self->append_conf(
'postgresql.conf', qq( 'postgresql.conf', qq(
primary_conninfo='$root_connstr application_name=$name' primary_conninfo='$root_connstr'
)); ));
$self->set_standby_mode(); $self->set_standby_mode();
return; return;
......
...@@ -50,7 +50,7 @@ is($psql_out, 't', "promotion of standby with pg_promote"); ...@@ -50,7 +50,7 @@ is($psql_out, 't', "promotion of standby with pg_promote");
my $connstr_1 = $node_standby_1->connstr; my $connstr_1 = $node_standby_1->connstr;
$node_standby_2->append_conf( $node_standby_2->append_conf(
'postgresql.conf', qq( 'postgresql.conf', qq(
primary_conninfo='$connstr_1 application_name=@{[$node_standby_2->name]}' primary_conninfo='$connstr_1'
)); ));
$node_standby_2->restart; $node_standby_2->restart;
......
...@@ -63,12 +63,11 @@ $node_publisher->safe_psql('postgres', ...@@ -63,12 +63,11 @@ $node_publisher->safe_psql('postgres',
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins"); "ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
my $appname = 'tap_sub';
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub, tap_pub_ins_only" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub, tap_pub_ins_only"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Also wait for initial table sync to finish # Also wait for initial table sync to finish
my $synced_query = my $synced_query =
...@@ -103,7 +102,7 @@ $node_publisher->safe_psql('postgres', ...@@ -103,7 +102,7 @@ $node_publisher->safe_psql('postgres',
"DELETE FROM tab_include WHERE a > 20"); "DELETE FROM tab_include WHERE a > 20");
$node_publisher->safe_psql('postgres', "UPDATE tab_include SET a = -a"); $node_publisher->safe_psql('postgres', "UPDATE tab_include SET a = -a");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins"); "SELECT count(*), min(a), max(a) FROM tab_ins");
...@@ -146,7 +145,7 @@ $node_publisher->safe_psql('postgres', "UPDATE tab_full SET a = a * a"); ...@@ -146,7 +145,7 @@ $node_publisher->safe_psql('postgres', "UPDATE tab_full SET a = a * a");
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'"); "UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_full"); "SELECT count(*), min(a), max(a) FROM tab_full");
...@@ -165,23 +164,23 @@ bb), ...@@ -165,23 +164,23 @@ bb),
# as we need to poll for a change but the test suite will fail none the less # as we need to poll for a change but the test suite will fail none the less
# when something goes wrong. # when something goes wrong.
my $oldpid = $node_publisher->safe_psql('postgres', my $oldpid = $node_publisher->safe_psql('postgres',
"SELECT pid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
); );
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"ALTER SUBSCRIPTION tap_sub CONNECTION 'application_name=$appname $publisher_connstr'" "ALTER SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr sslmode=disable'"
); );
$node_publisher->poll_query_until('postgres', $node_publisher->poll_query_until('postgres',
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
) or die "Timed out while waiting for apply to restart"; ) or die "Timed out while waiting for apply to restart";
$oldpid = $node_publisher->safe_psql('postgres', $oldpid = $node_publisher->safe_psql('postgres',
"SELECT pid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
); );
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_only WITH (copy_data = false)" "ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_only WITH (copy_data = false)"
); );
$node_publisher->poll_query_until('postgres', $node_publisher->poll_query_until('postgres',
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
) or die "Timed out while waiting for apply to restart"; ) or die "Timed out while waiting for apply to restart";
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
...@@ -193,7 +192,7 @@ $node_publisher->safe_psql('postgres', "DELETE FROM tab_rep"); ...@@ -193,7 +192,7 @@ $node_publisher->safe_psql('postgres', "DELETE FROM tab_rep");
$node_publisher->stop('fast'); $node_publisher->stop('fast');
$node_publisher->start; $node_publisher->start;
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), min(a), max(a) FROM tab_ins"); "SELECT count(*), min(a), max(a) FROM tab_ins");
...@@ -216,7 +215,7 @@ $node_subscriber->safe_psql('postgres', ...@@ -216,7 +215,7 @@ $node_subscriber->safe_psql('postgres',
); );
$node_publisher->safe_psql('postgres', "INSERT INTO tab_full VALUES(0)"); $node_publisher->safe_psql('postgres', "INSERT INTO tab_full VALUES(0)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# note that data are different on provider and subscriber # note that data are different on provider and subscriber
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
...@@ -230,12 +229,12 @@ is($result, qq(21|0|100), 'check replicated insert after alter publication'); ...@@ -230,12 +229,12 @@ is($result, qq(21|0|100), 'check replicated insert after alter publication');
# check restart on rename # check restart on rename
$oldpid = $node_publisher->safe_psql('postgres', $oldpid = $node_publisher->safe_psql('postgres',
"SELECT pid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid FROM pg_stat_replication WHERE application_name = 'tap_sub';"
); );
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"ALTER SUBSCRIPTION tap_sub RENAME TO tap_sub_renamed"); "ALTER SUBSCRIPTION tap_sub RENAME TO tap_sub_renamed");
$node_publisher->poll_query_until('postgres', $node_publisher->poll_query_until('postgres',
"SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = '$appname';" "SELECT pid != $oldpid FROM pg_stat_replication WHERE application_name = 'tap_sub_renamed';"
) or die "Timed out while waiting for apply to restart"; ) or die "Timed out while waiting for apply to restart";
# check all the cleanup # check all the cleanup
......
...@@ -107,12 +107,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; ...@@ -107,12 +107,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION tap_pub FOR ALL TABLES"); "CREATE PUBLICATION tap_pub FOR ALL TABLES");
my $appname = 'tap_sub';
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub WITH (slot_name = tap_sub_slot)" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (slot_name = tap_sub_slot)"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Wait for initial sync to finish as well # Wait for initial sync to finish as well
my $synced_query = my $synced_query =
...@@ -251,7 +250,7 @@ $node_publisher->safe_psql( ...@@ -251,7 +250,7 @@ $node_publisher->safe_psql(
INSERT INTO tst_dom_constr VALUES (10); INSERT INTO tst_dom_constr VALUES (10);
)); ));
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Check the data on subscriber # Check the data on subscriber
my $result = $node_subscriber->safe_psql( my $result = $node_subscriber->safe_psql(
...@@ -372,7 +371,7 @@ $node_publisher->safe_psql( ...@@ -372,7 +371,7 @@ $node_publisher->safe_psql(
UPDATE tst_hstore SET b = '"also"=>"updated"' WHERE a = 3; UPDATE tst_hstore SET b = '"also"=>"updated"' WHERE a = 3;
)); ));
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Check the data on subscriber # Check the data on subscriber
$result = $node_subscriber->safe_psql( $result = $node_subscriber->safe_psql(
...@@ -492,7 +491,7 @@ $node_publisher->safe_psql( ...@@ -492,7 +491,7 @@ $node_publisher->safe_psql(
DELETE FROM tst_hstore WHERE a = 1; DELETE FROM tst_hstore WHERE a = 1;
)); ));
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Check the data on subscriber # Check the data on subscriber
$result = $node_subscriber->safe_psql( $result = $node_subscriber->safe_psql(
...@@ -554,7 +553,7 @@ e|{e,d} ...@@ -554,7 +553,7 @@ e|{e,d}
# which needs an active snapshot in order to operate. # which needs an active snapshot in order to operate.
$node_publisher->safe_psql('postgres', "INSERT INTO tst_dom_constr VALUES (11)"); $node_publisher->safe_psql('postgres', "INSERT INTO tst_dom_constr VALUES (11)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $result =
$node_subscriber->safe_psql('postgres', "SELECT sum(a) FROM tst_dom_constr"); $node_subscriber->safe_psql('postgres', "SELECT sum(a) FROM tst_dom_constr");
......
...@@ -34,19 +34,18 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; ...@@ -34,19 +34,18 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION tap_pub FOR ALL TABLES;"); "CREATE PUBLICATION tap_pub FOR ALL TABLES;");
my $appname = 'tap_sub';
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub WITH (copy_data = false)" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (copy_data = false)"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO tab_fk (bid) VALUES (1);"); "INSERT INTO tab_fk (bid) VALUES (1);");
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO tab_fk_ref (id, bid) VALUES (1, 1);"); "INSERT INTO tab_fk_ref (id, bid) VALUES (1, 1);");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Check data on subscriber # Check data on subscriber
my $result = $node_subscriber->safe_psql('postgres', my $result = $node_subscriber->safe_psql('postgres',
...@@ -64,7 +63,7 @@ $node_publisher->safe_psql('postgres', "DROP TABLE tab_fk CASCADE;"); ...@@ -64,7 +63,7 @@ $node_publisher->safe_psql('postgres', "DROP TABLE tab_fk CASCADE;");
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO tab_fk_ref (id, bid) VALUES (2, 2);"); "INSERT INTO tab_fk_ref (id, bid) VALUES (2, 2);");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# FK is not enforced on subscriber # FK is not enforced on subscriber
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
...@@ -98,7 +97,7 @@ ALTER TABLE tab_fk_ref ENABLE REPLICA TRIGGER filter_basic_dml_trg; ...@@ -98,7 +97,7 @@ ALTER TABLE tab_fk_ref ENABLE REPLICA TRIGGER filter_basic_dml_trg;
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO tab_fk_ref (id, bid) VALUES (10, 10);"); "INSERT INTO tab_fk_ref (id, bid) VALUES (10, 10);");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# The row should be skipped on subscriber # The row should be skipped on subscriber
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
......
...@@ -32,12 +32,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; ...@@ -32,12 +32,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION tap_pub FOR ALL TABLES"); "CREATE PUBLICATION tap_pub FOR ALL TABLES");
my $appname = 'tap_sub';
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Also wait for initial table sync to finish # Also wait for initial table sync to finish
my $synced_query = my $synced_query =
...@@ -57,7 +56,7 @@ $node_publisher->safe_psql('postgres', ...@@ -57,7 +56,7 @@ $node_publisher->safe_psql('postgres',
# recreate the subscription, it will try to do initial copy # recreate the subscription, it will try to do initial copy
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
); );
# but it will be stuck on data copy as it will fail on constraint # but it will be stuck on data copy as it will fail on constraint
...@@ -79,7 +78,7 @@ is($result, qq(20), 'initial data synced for second sub'); ...@@ -79,7 +78,7 @@ is($result, qq(20), 'initial data synced for second sub');
# now check another subscription for the same node pair # now check another subscription for the same node pair
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub2 CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub WITH (copy_data = false)" "CREATE SUBSCRIPTION tap_sub2 CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (copy_data = false)"
); );
# wait for it to start # wait for it to start
...@@ -101,7 +100,7 @@ $node_subscriber->safe_psql('postgres', "DELETE FROM tab_rep;"); ...@@ -101,7 +100,7 @@ $node_subscriber->safe_psql('postgres', "DELETE FROM tab_rep;");
# recreate the subscription again # recreate the subscription again
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
); );
# and wait for data sync to finish again # and wait for data sync to finish again
...@@ -120,7 +119,7 @@ $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_rep_next (a int)"); ...@@ -120,7 +119,7 @@ $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_rep_next (a int)");
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE TABLE tab_rep_next (a) AS SELECT generate_series(1,10)"); "CREATE TABLE tab_rep_next (a) AS SELECT generate_series(1,10)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM tab_rep_next"); "SELECT count(*) FROM tab_rep_next");
...@@ -143,7 +142,7 @@ is($result, qq(10), ...@@ -143,7 +142,7 @@ is($result, qq(10),
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO tab_rep_next SELECT generate_series(1,10)"); "INSERT INTO tab_rep_next SELECT generate_series(1,10)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM tab_rep_next"); "SELECT count(*) FROM tab_rep_next");
......
...@@ -22,15 +22,14 @@ $node_publisher->safe_psql('postgres', $ddl); ...@@ -22,15 +22,14 @@ $node_publisher->safe_psql('postgres', $ddl);
$node_subscriber->safe_psql('postgres', $ddl); $node_subscriber->safe_psql('postgres', $ddl);
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
my $appname = 'encoding_test';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION mypub FOR ALL TABLES;"); "CREATE PUBLICATION mypub FOR ALL TABLES;");
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION mypub;" "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
# Wait for initial sync to finish as well # Wait for initial sync to finish as well
my $synced_query = my $synced_query =
...@@ -41,7 +40,7 @@ $node_subscriber->poll_query_until('postgres', $synced_query) ...@@ -41,7 +40,7 @@ $node_subscriber->poll_query_until('postgres', $synced_query)
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
q{INSERT INTO test1 VALUES (1, E'Mot\xc3\xb6rhead')}); # hand-rolled UTF-8 q{INSERT INTO test1 VALUES (1, E'Mot\xc3\xb6rhead')}); # hand-rolled UTF-8
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
is( $node_subscriber->safe_psql( is( $node_subscriber->safe_psql(
'postgres', q{SELECT a FROM test1 WHERE b = E'Mot\xf6rhead'} 'postgres', q{SELECT a FROM test1 WHERE b = E'Mot\xf6rhead'}
......
...@@ -18,15 +18,14 @@ $node_publisher->safe_psql('postgres', $ddl); ...@@ -18,15 +18,14 @@ $node_publisher->safe_psql('postgres', $ddl);
$node_subscriber->safe_psql('postgres', $ddl); $node_subscriber->safe_psql('postgres', $ddl);
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
my $appname = 'encoding_test';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION mypub FOR ALL TABLES;"); "CREATE PUBLICATION mypub FOR ALL TABLES;");
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION mypub;" "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
# Wait for initial sync to finish as well # Wait for initial sync to finish as well
my $synced_query = my $synced_query =
...@@ -37,7 +36,7 @@ $node_subscriber->poll_query_until('postgres', $synced_query) ...@@ -37,7 +36,7 @@ $node_subscriber->poll_query_until('postgres', $synced_query)
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');}); q{INSERT INTO test1 (a, b) VALUES (1, 'one'), (2, 'two');});
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
is( $node_subscriber->safe_psql('postgres', q{SELECT a, b FROM test1}), is( $node_subscriber->safe_psql('postgres', q{SELECT a, b FROM test1}),
qq(1|one qq(1|one
...@@ -49,12 +48,12 @@ my $ddl2 = "ALTER TABLE test1 ADD c int NOT NULL DEFAULT 0;"; ...@@ -49,12 +48,12 @@ my $ddl2 = "ALTER TABLE test1 ADD c int NOT NULL DEFAULT 0;";
$node_subscriber->safe_psql('postgres', $ddl2); $node_subscriber->safe_psql('postgres', $ddl2);
$node_publisher->safe_psql('postgres', $ddl2); $node_publisher->safe_psql('postgres', $ddl2);
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
q{INSERT INTO test1 (a, b, c) VALUES (3, 'three', 33);}); q{INSERT INTO test1 (a, b, c) VALUES (3, 'three', 33);});
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
is( $node_subscriber->safe_psql('postgres', q{SELECT a, b, c FROM test1}), is( $node_subscriber->safe_psql('postgres', q{SELECT a, b, c FROM test1}),
qq(1|one|0 qq(1|one|0
......
...@@ -18,15 +18,14 @@ $node_publisher->safe_psql('postgres', $ddl); ...@@ -18,15 +18,14 @@ $node_publisher->safe_psql('postgres', $ddl);
$node_subscriber->safe_psql('postgres', $ddl); $node_subscriber->safe_psql('postgres', $ddl);
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
my $appname = 'replication_test';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION mypub FOR ALL TABLES;"); "CREATE PUBLICATION mypub FOR ALL TABLES;");
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION mypub;" "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
$node_subscriber->safe_psql( $node_subscriber->safe_psql(
'postgres', q{ 'postgres', q{
......
...@@ -31,12 +31,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; ...@@ -31,12 +31,11 @@ my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION tap_pub FOR TABLE test_tab"); "CREATE PUBLICATION tap_pub FOR TABLE test_tab");
my $appname = 'tap_sub';
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub" "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub"
); );
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
# Also wait for initial table sync to finish # Also wait for initial table sync to finish
my $synced_query = my $synced_query =
...@@ -53,7 +52,7 @@ is($result, qq(2|2|2), 'check initial data was copied to subscriber'); ...@@ -53,7 +52,7 @@ is($result, qq(2|2|2), 'check initial data was copied to subscriber');
# subscriber didn't change # subscriber didn't change
$node_publisher->safe_psql('postgres', "UPDATE test_tab SET b = md5(b)"); $node_publisher->safe_psql('postgres', "UPDATE test_tab SET b = md5(b)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $result =
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
...@@ -70,7 +69,7 @@ $node_subscriber->safe_psql('postgres', ...@@ -70,7 +69,7 @@ $node_subscriber->safe_psql('postgres',
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"UPDATE test_tab SET b = md5(a::text)"); "UPDATE test_tab SET b = md5(a::text)");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $node_subscriber->safe_psql('postgres', $result = $node_subscriber->safe_psql('postgres',
"SELECT count(*), count(extract(epoch from c) = 987654321), count(d = 999) FROM test_tab" "SELECT count(*), count(extract(epoch from c) = 987654321), count(d = 999) FROM test_tab"
...@@ -81,7 +80,7 @@ is($result, qq(2|2|2), 'check extra columns contain locally changed data'); ...@@ -81,7 +80,7 @@ is($result, qq(2|2|2), 'check extra columns contain locally changed data');
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"INSERT INTO test_tab VALUES (3, 'baz')"); "INSERT INTO test_tab VALUES (3, 'baz')");
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('tap_sub');
$result = $result =
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
......
...@@ -14,12 +14,11 @@ $node_subscriber->init(allows_streaming => 'logical'); ...@@ -14,12 +14,11 @@ $node_subscriber->init(allows_streaming => 'logical');
$node_subscriber->start; $node_subscriber->start;
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres'; my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
my $appname = 'replication_test';
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION mypub FOR ALL TABLES;"); "CREATE PUBLICATION mypub FOR ALL TABLES;");
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION mypub;" "CREATE SUBSCRIPTION mysub CONNECTION '$publisher_connstr' PUBLICATION mypub;"
); );
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
...@@ -30,7 +29,7 @@ $node_publisher->safe_psql('postgres', ...@@ -30,7 +29,7 @@ $node_publisher->safe_psql('postgres',
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
q{CREATE TABLE test1 (a int PRIMARY KEY, b text);}); q{CREATE TABLE test1 (a int PRIMARY KEY, b text);});
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
# Materialized views are not supported by logical replication, but # Materialized views are not supported by logical replication, but
# logical decoding does produce change information for them, so we # logical decoding does produce change information for them, so we
...@@ -39,7 +38,7 @@ $node_publisher->wait_for_catchup($appname); ...@@ -39,7 +38,7 @@ $node_publisher->wait_for_catchup($appname);
# create a MV with some data # create a MV with some data
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;}); q{CREATE MATERIALIZED VIEW testmv1 AS SELECT * FROM test1;});
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup('mysub');
# There is no equivalent relation on the subscriber, but MV data is # There is no equivalent relation on the subscriber, but MV data is
# not replicated, so this does not hang. # not replicated, so this does not hang.
......
...@@ -52,13 +52,13 @@ $node_publisher->safe_psql('postgres', ...@@ -52,13 +52,13 @@ $node_publisher->safe_psql('postgres',
$node_publisher->safe_psql('postgres', $node_publisher->safe_psql('postgres',
"CREATE PUBLICATION pub3 FOR TABLE tab3, tab4"); "CREATE PUBLICATION pub3 FOR TABLE tab3, tab4");
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr application_name=sub1' PUBLICATION pub1" "CREATE SUBSCRIPTION sub1 CONNECTION '$publisher_connstr' PUBLICATION pub1"
); );
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION sub2 CONNECTION '$publisher_connstr application_name=sub2' PUBLICATION pub2" "CREATE SUBSCRIPTION sub2 CONNECTION '$publisher_connstr' PUBLICATION pub2"
); );
$node_subscriber->safe_psql('postgres', $node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION sub3 CONNECTION '$publisher_connstr application_name=sub3' PUBLICATION pub3" "CREATE SUBSCRIPTION sub3 CONNECTION '$publisher_connstr' PUBLICATION pub3"
); );
# Wait for initial sync of all subscriptions # Wait for initial sync of all subscriptions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment