diff options
Diffstat (limited to 'src/test/recovery/t/001_stream_rep.pl')
-rw-r--r-- | src/test/recovery/t/001_stream_rep.pl | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/001_stream_rep.pl index 778f11b28b4..9e31a53de77 100644 --- a/src/test/recovery/t/001_stream_rep.pl +++ b/src/test/recovery/t/001_stream_rep.pl @@ -5,22 +5,22 @@ use PostgresNode; use TestLib; use Test::More tests => 36; -# Initialize master node -my $node_master = get_new_node('master'); +# Initialize primary node +my $node_primary = get_new_node('primary'); # A specific role is created to perform some tests related to replication, # and it needs proper authentication configuration. -$node_master->init( +$node_primary->init( allows_streaming => 1, auth_extra => [ '--create-role', 'repl_role' ]); -$node_master->start; +$node_primary->start; my $backup_name = 'my_backup'; # Take backup -$node_master->backup($backup_name); +$node_primary->backup($backup_name); -# Create streaming standby linking to master +# Create streaming standby linking to primary my $node_standby_1 = get_new_node('standby_1'); -$node_standby_1->init_from_backup($node_master, $backup_name, +$node_standby_1->init_from_backup($node_primary, $backup_name, has_streaming => 1); $node_standby_1->start; @@ -28,10 +28,10 @@ $node_standby_1->start; # pg_basebackup works on a standby). $node_standby_1->backup($backup_name); -# Take a second backup of the standby while the master is offline. -$node_master->stop; +# Take a second backup of the standby while the primary is offline. +$node_primary->stop; $node_standby_1->backup('my_backup_2'); -$node_master->start; +$node_primary->start; # Create second standby node linking to standby 1 my $node_standby_2 = get_new_node('standby_2'); @@ -39,13 +39,13 @@ $node_standby_2->init_from_backup($node_standby_1, $backup_name, has_streaming => 1); $node_standby_2->start; -# Create some content on master and check its presence in standby 1 -$node_master->safe_psql('postgres', +# Create some content on primary and check its presence in standby 1 +$node_primary->safe_psql('postgres', "CREATE TABLE tab_int AS SELECT generate_series(1,1002) AS a"); # Wait for standbys to catch up -$node_master->wait_for_catchup($node_standby_1, 'replay', - $node_master->lsn('insert')); +$node_primary->wait_for_catchup($node_standby_1, 'replay', + $node_primary->lsn('insert')); $node_standby_1->wait_for_catchup($node_standby_2, 'replay', $node_standby_1->lsn('replay')); @@ -105,57 +105,57 @@ sub test_target_session_attrs return; } -# Connect to master in "read-write" mode with master,standby1 list. -test_target_session_attrs($node_master, $node_standby_1, $node_master, +# Connect to primary in "read-write" mode with primary,standby1 list. +test_target_session_attrs($node_primary, $node_standby_1, $node_primary, "read-write", 0); -# Connect to master in "read-write" mode with standby1,master list. -test_target_session_attrs($node_standby_1, $node_master, $node_master, +# Connect to primary in "read-write" mode with standby1,primary list. +test_target_session_attrs($node_standby_1, $node_primary, $node_primary, "read-write", 0); -# Connect to master in "any" mode with master,standby1 list. -test_target_session_attrs($node_master, $node_standby_1, $node_master, "any", +# Connect to primary in "any" mode with primary,standby1 list. +test_target_session_attrs($node_primary, $node_standby_1, $node_primary, "any", 0); -# Connect to standby1 in "any" mode with standby1,master list. -test_target_session_attrs($node_standby_1, $node_master, $node_standby_1, +# Connect to standby1 in "any" mode with standby1,primary list. +test_target_session_attrs($node_standby_1, $node_primary, $node_standby_1, "any", 0); # Test for SHOW commands using a WAL sender connection with a replication # role. note "testing SHOW commands for replication connection"; -$node_master->psql( +$node_primary->psql( 'postgres', " CREATE ROLE repl_role REPLICATION LOGIN; GRANT pg_read_all_settings TO repl_role;"); -my $master_host = $node_master->host; -my $master_port = $node_master->port; -my $connstr_common = "host=$master_host port=$master_port user=repl_role"; +my $primary_host = $node_primary->host; +my $primary_port = $node_primary->port; +my $connstr_common = "host=$primary_host port=$primary_port user=repl_role"; my $connstr_rep = "$connstr_common replication=1"; my $connstr_db = "$connstr_common replication=database dbname=postgres"; # Test SHOW ALL -my ($ret, $stdout, $stderr) = $node_master->psql( +my ($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW ALL;', on_error_die => 1, extra_params => [ '-d', $connstr_rep ]); ok($ret == 0, "SHOW ALL with replication role and physical replication"); -($ret, $stdout, $stderr) = $node_master->psql( +($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW ALL;', on_error_die => 1, extra_params => [ '-d', $connstr_db ]); ok($ret == 0, "SHOW ALL with replication role and logical replication"); # Test SHOW with a user-settable parameter -($ret, $stdout, $stderr) = $node_master->psql( +($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW work_mem;', on_error_die => 1, extra_params => [ '-d', $connstr_rep ]); ok( $ret == 0, "SHOW with user-settable parameter, replication role and physical replication" ); -($ret, $stdout, $stderr) = $node_master->psql( +($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW work_mem;', on_error_die => 1, extra_params => [ '-d', $connstr_db ]); @@ -164,14 +164,14 @@ ok( $ret == 0, ); # Test SHOW with a superuser-settable parameter -($ret, $stdout, $stderr) = $node_master->psql( +($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW primary_conninfo;', on_error_die => 1, extra_params => [ '-d', $connstr_rep ]); ok( $ret == 0, "SHOW with superuser-settable parameter, replication role and physical replication" ); -($ret, $stdout, $stderr) = $node_master->psql( +($ret, $stdout, $stderr) = $node_primary->psql( 'postgres', 'SHOW primary_conninfo;', on_error_die => 1, extra_params => [ '-d', $connstr_db ]); @@ -186,13 +186,13 @@ note "switching to physical replication slot"; # standbys. Since we're going to be testing things that affect the slot state, # also increase the standby feedback interval to ensure timely updates. my ($slotname_1, $slotname_2) = ('standby_1', 'standby_2'); -$node_master->append_conf('postgresql.conf', "max_replication_slots = 4"); -$node_master->restart; -is( $node_master->psql( +$node_primary->append_conf('postgresql.conf', "max_replication_slots = 4"); +$node_primary->restart; +is( $node_primary->psql( 'postgres', qq[SELECT pg_create_physical_replication_slot('$slotname_1');]), 0, - 'physical slot created on master'); + 'physical slot created on primary'); $node_standby_1->append_conf('postgresql.conf', "primary_slot_name = $slotname_1"); $node_standby_1->append_conf('postgresql.conf', @@ -231,7 +231,7 @@ sub get_slot_xmins # There's no hot standby feedback and there are no logical slots on either peer # so xmin and catalog_xmin should be null on both slots. -my ($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1, +my ($xmin, $catalog_xmin) = get_slot_xmins($node_primary, $slotname_1, "xmin IS NULL AND catalog_xmin IS NULL"); is($xmin, '', 'xmin of non-cascaded slot null with no hs_feedback'); is($catalog_xmin, '', @@ -244,20 +244,20 @@ is($catalog_xmin, '', 'catalog xmin of cascaded slot null with no hs_feedback'); # Replication still works? -$node_master->safe_psql('postgres', 'CREATE TABLE replayed(val integer);'); +$node_primary->safe_psql('postgres', 'CREATE TABLE replayed(val integer);'); sub replay_check { - my $newval = $node_master->safe_psql('postgres', + my $newval = $node_primary->safe_psql('postgres', 'INSERT INTO replayed(val) SELECT coalesce(max(val),0) + 1 AS newval FROM replayed RETURNING val' ); - $node_master->wait_for_catchup($node_standby_1, 'replay', - $node_master->lsn('insert')); + $node_primary->wait_for_catchup($node_standby_1, 'replay', + $node_primary->lsn('insert')); $node_standby_1->wait_for_catchup($node_standby_2, 'replay', $node_standby_1->lsn('replay')); $node_standby_1->safe_psql('postgres', qq[SELECT 1 FROM replayed WHERE val = $newval]) - or die "standby_1 didn't replay master value $newval"; + or die "standby_1 didn't replay primary value $newval"; $node_standby_2->safe_psql('postgres', qq[SELECT 1 FROM replayed WHERE val = $newval]) or die "standby_2 didn't replay standby_1 value $newval"; @@ -278,7 +278,7 @@ $node_standby_2->safe_psql('postgres', $node_standby_2->reload; replay_check(); -($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1, +($xmin, $catalog_xmin) = get_slot_xmins($node_primary, $slotname_1, "xmin IS NOT NULL AND catalog_xmin IS NULL"); isnt($xmin, '', 'xmin of non-cascaded slot non-null with hs feedback'); is($catalog_xmin, '', @@ -291,7 +291,7 @@ is($catalog_xmin1, '', 'catalog xmin of cascaded slot still null with hs_feedback'); note "doing some work to advance xmin"; -$node_master->safe_psql( +$node_primary->safe_psql( 'postgres', q{ do $$ begin @@ -306,12 +306,12 @@ begin end$$; }); -$node_master->safe_psql('postgres', 'VACUUM;'); -$node_master->safe_psql('postgres', 'CHECKPOINT;'); +$node_primary->safe_psql('postgres', 'VACUUM;'); +$node_primary->safe_psql('postgres', 'CHECKPOINT;'); my ($xmin2, $catalog_xmin2) = - get_slot_xmins($node_master, $slotname_1, "xmin <> '$xmin'"); -note "master slot's new xmin $xmin2, old xmin $xmin"; + get_slot_xmins($node_primary, $slotname_1, "xmin <> '$xmin'"); +note "primary slot's new xmin $xmin2, old xmin $xmin"; isnt($xmin2, $xmin, 'xmin of non-cascaded slot with hs feedback has changed'); is($catalog_xmin2, '', 'catalog xmin of non-cascaded slot still null with hs_feedback unchanged' @@ -335,7 +335,7 @@ $node_standby_2->safe_psql('postgres', $node_standby_2->reload; replay_check(); -($xmin, $catalog_xmin) = get_slot_xmins($node_master, $slotname_1, +($xmin, $catalog_xmin) = get_slot_xmins($node_primary, $slotname_1, "xmin IS NULL AND catalog_xmin IS NULL"); is($xmin, '', 'xmin of non-cascaded slot null with hs feedback reset'); is($catalog_xmin, '', @@ -349,55 +349,55 @@ is($catalog_xmin, '', note "check change primary_conninfo without restart"; $node_standby_2->append_conf('postgresql.conf', "primary_slot_name = ''"); -$node_standby_2->enable_streaming($node_master); +$node_standby_2->enable_streaming($node_primary); $node_standby_2->reload; # be sure do not streaming from cascade $node_standby_1->stop; -my $newval = $node_master->safe_psql('postgres', +my $newval = $node_primary->safe_psql('postgres', 'INSERT INTO replayed(val) SELECT coalesce(max(val),0) + 1 AS newval FROM replayed RETURNING val' ); -$node_master->wait_for_catchup($node_standby_2, 'replay', - $node_master->lsn('insert')); +$node_primary->wait_for_catchup($node_standby_2, 'replay', + $node_primary->lsn('insert')); my $is_replayed = $node_standby_2->safe_psql('postgres', qq[SELECT 1 FROM replayed WHERE val = $newval]); -is($is_replayed, qq(1), "standby_2 didn't replay master value $newval"); +is($is_replayed, qq(1), "standby_2 didn't replay primary value $newval"); # Drop any existing slots on the primary, for the follow-up tests. -$node_master->safe_psql('postgres', +$node_primary->safe_psql('postgres', "SELECT pg_drop_replication_slot(slot_name) FROM pg_replication_slots;"); # Test physical slot advancing and its durability. Create a new slot on # the primary, not used by any of the standbys. This reserves WAL at creation. my $phys_slot = 'phys_slot'; -$node_master->safe_psql('postgres', +$node_primary->safe_psql('postgres', "SELECT pg_create_physical_replication_slot('$phys_slot', true);"); # Generate some WAL, and switch to a new segment, used to check that # the previous segment is correctly getting recycled as the slot advancing # would recompute the minimum LSN calculated across all slots. -my $segment_removed = $node_master->safe_psql('postgres', +my $segment_removed = $node_primary->safe_psql('postgres', 'SELECT pg_walfile_name(pg_current_wal_lsn())'); chomp($segment_removed); -$node_master->psql( +$node_primary->psql( 'postgres', " CREATE TABLE tab_phys_slot (a int); INSERT INTO tab_phys_slot VALUES (generate_series(1,10)); SELECT pg_switch_wal();"); my $current_lsn = - $node_master->safe_psql('postgres', "SELECT pg_current_wal_lsn();"); + $node_primary->safe_psql('postgres', "SELECT pg_current_wal_lsn();"); chomp($current_lsn); -my $psql_rc = $node_master->psql('postgres', +my $psql_rc = $node_primary->psql('postgres', "SELECT pg_replication_slot_advance('$phys_slot', '$current_lsn'::pg_lsn);" ); is($psql_rc, '0', 'slot advancing with physical slot'); -my $phys_restart_lsn_pre = $node_master->safe_psql('postgres', +my $phys_restart_lsn_pre = $node_primary->safe_psql('postgres', "SELECT restart_lsn from pg_replication_slots WHERE slot_name = '$phys_slot';" ); chomp($phys_restart_lsn_pre); # Slot advance should persist across clean restarts. -$node_master->restart; -my $phys_restart_lsn_post = $node_master->safe_psql('postgres', +$node_primary->restart; +my $phys_restart_lsn_post = $node_primary->safe_psql('postgres', "SELECT restart_lsn from pg_replication_slots WHERE slot_name = '$phys_slot';" ); chomp($phys_restart_lsn_post); @@ -406,6 +406,6 @@ ok( ($phys_restart_lsn_pre cmp $phys_restart_lsn_post) == 0, # Check if the previous segment gets correctly recycled after the # server stopped cleanly, causing a shutdown checkpoint to be generated. -my $master_data = $node_master->data_dir; -ok(!-f "$master_data/pg_wal/$segment_removed", +my $primary_data = $node_primary->data_dir; +ok(!-f "$primary_data/pg_wal/$segment_removed", "WAL segment $segment_removed recycled after physical slot advancing"); |