1 # Test for timeline switch
2 # Ensure that a cascading standby is able to follow a newly-promoted standby
6 use File::Path qw(rmtree);
9 use Test::More tests => 1;
11 $ENV{PGDATABASE} = 'postgres';
13 # Initialize master node
14 my $node_master = get_new_node('master');
15 $node_master->init(allows_streaming => 1);
19 my $backup_name = 'my_backup';
20 $node_master->backup($backup_name);
22 # Create two standbys linking to it
23 my $node_standby_1 = get_new_node('standby_1');
24 $node_standby_1->init_from_backup($node_master, $backup_name,
26 $node_standby_1->start;
27 my $node_standby_2 = get_new_node('standby_2');
28 $node_standby_2->init_from_backup($node_master, $backup_name,
30 $node_standby_2->start;
32 # Create some content on master
33 $node_master->safe_psql('postgres',
34 "CREATE TABLE tab_int AS SELECT generate_series(1,1000) AS a");
36 # Wait until standby has replayed enough data on standby 1
37 $node_master->wait_for_catchup($node_standby_1, 'replay', $node_master->lsn('write'));
39 # Stop and remove master, and promote standby 1, switching it to a new timeline
40 $node_master->teardown_node;
41 $node_standby_1->promote;
43 # Switch standby 2 to replay from standby 1
44 rmtree($node_standby_2->data_dir . '/recovery.conf');
45 my $connstr_1 = $node_standby_1->connstr;
46 $node_standby_2->append_conf(
48 primary_conninfo='$connstr_1 application_name=@{[$node_standby_2->name]}'
50 recovery_target_timeline='latest'
52 $node_standby_2->restart;
54 # Insert some data in standby 1 and check its presence in standby 2
55 # to ensure that the timeline switch has been done.
56 $node_standby_1->safe_psql('postgres',
57 "INSERT INTO tab_int VALUES (generate_series(1001,2000))");
58 $node_standby_1->wait_for_catchup($node_standby_2, 'replay', $node_standby_1->lsn('write'));
61 $node_standby_2->safe_psql('postgres', "SELECT count(*) FROM tab_int");
62 is($result, qq(2000), 'check content of standby 2');