mirror of
https://github.com/postgres/postgres.git
synced 2025-06-01 00:01:20 -04:00
This was nearly the same code. Extend wait_for_catchup to allow waiting for pg_current_wal_lsn() and use that in the subscription tests. Also change one use in the pg_rewind tests to use this. Also remove some broken code in wait_for_catchup and wait_for_slot_catchup. The error message in case the waiting failed wanted to show the current LSN, but the way it was written never worked. So since nobody ever cared, just remove it. Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
72 lines
2.7 KiB
Perl
72 lines
2.7 KiB
Perl
# Test behavior with different schema on subscriber
|
|
use strict;
|
|
use warnings;
|
|
use PostgresNode;
|
|
use TestLib;
|
|
use Test::More tests => 3;
|
|
|
|
# Create publisher node
|
|
my $node_publisher = get_new_node('publisher');
|
|
$node_publisher->init(allows_streaming => 'logical');
|
|
$node_publisher->start;
|
|
|
|
# Create subscriber node
|
|
my $node_subscriber = get_new_node('subscriber');
|
|
$node_subscriber->init(allows_streaming => 'logical');
|
|
$node_subscriber->start;
|
|
|
|
# Create some preexisting content on publisher
|
|
$node_publisher->safe_psql('postgres',
|
|
"CREATE TABLE test_tab (a int primary key, b varchar)");
|
|
$node_publisher->safe_psql('postgres',
|
|
"INSERT INTO test_tab VALUES (1, 'foo'), (2, 'bar')");
|
|
|
|
# Setup structure on subscriber
|
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE test_tab (a int primary key, b text, c timestamptz DEFAULT now(), d bigint DEFAULT 999)");
|
|
|
|
# Setup logical replication
|
|
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
|
|
$node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub FOR TABLE test_tab");
|
|
|
|
my $appname = 'tap_sub';
|
|
$node_subscriber->safe_psql('postgres',
|
|
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub"
|
|
);
|
|
|
|
$node_publisher->wait_for_catchup($appname);
|
|
|
|
# Also wait for initial table sync to finish
|
|
my $synced_query =
|
|
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');";
|
|
$node_subscriber->poll_query_until('postgres', $synced_query)
|
|
or die "Timed out while waiting for subscriber to synchronize data";
|
|
|
|
my $result =
|
|
$node_subscriber->safe_psql('postgres', "SELECT count(*), count(c), count(d = 999) FROM test_tab");
|
|
is($result, qq(2|2|2), 'check initial data was copied to subscriber');
|
|
|
|
# Update the rows on the publisher and check the additional columns on
|
|
# subscriber didn't change
|
|
$node_publisher->safe_psql('postgres', "UPDATE test_tab SET b = md5(b)");
|
|
|
|
$node_publisher->wait_for_catchup($appname);
|
|
|
|
$result =
|
|
$node_subscriber->safe_psql('postgres', "SELECT count(*), count(c), count(d = 999) FROM test_tab");
|
|
is($result, qq(2|2|2), 'check extra columns contain local defaults');
|
|
|
|
# Change the local values of the extra columns on the subscriber,
|
|
# update publisher, and check that subscriber retains the expected
|
|
# values
|
|
$node_subscriber->safe_psql('postgres', "UPDATE test_tab SET c = 'epoch'::timestamptz + 987654321 * interval '1s'");
|
|
$node_publisher->safe_psql('postgres', "UPDATE test_tab SET b = md5(a::text)");
|
|
|
|
$node_publisher->wait_for_catchup($appname);
|
|
|
|
$result =
|
|
$node_subscriber->safe_psql('postgres', "SELECT count(*), count(extract(epoch from c) = 987654321), count(d = 999) FROM test_tab");
|
|
is($result, qq(2|2|2), 'check extra columns contain locally changed data');
|
|
|
|
$node_subscriber->stop;
|
|
$node_publisher->stop;
|