diff --git a/src/bin/pg_rewind/t/008_min_recovery_point.pl b/src/bin/pg_rewind/t/008_min_recovery_point.pl index d8ea33ab57c..f9c2cf41ba5 100644 --- a/src/bin/pg_rewind/t/008_min_recovery_point.pl +++ b/src/bin/pg_rewind/t/008_min_recovery_point.pl @@ -80,6 +80,13 @@ $node_3->poll_query_until('postgres', $caughtup_query) # $node_1->stop('fast'); $node_3->promote; +# Force a checkpoint after the promotion. pg_rewind looks at the control +# file to determine what timeline the server is on, and that isn't updated +# immediately at promotion, but only at the next checkpoint. When running +# pg_rewind in remote mode, it's possible that we complete the test steps +# after promotion so quickly that when pg_rewind runs, the standby has not +# performed a checkpoint after promotion yet. +$node_3->safe_psql('postgres', "checkpoint"); # reconfigure node_1 as a standby following node_3 rmtree $node_1->data_dir; @@ -116,6 +123,8 @@ $node_1->poll_query_until('postgres', $caughtup_query) or die "Timed out while waiting for standby to catch up"; $node_1->promote; +# Force a checkpoint after promotion, like earlier. +$node_1->safe_psql('postgres', "checkpoint"); # Wait until nodes 1 and 3 have been fully promoted. $node_1->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true"); @@ -127,6 +136,9 @@ $node_3->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true"); # see the insert on 1, as the insert on node 3 is rewound away. # $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('keep this')"); +# 'bar' is unmodified in node 1, so it won't be overwritten by replaying the +# WAL from node 1. +$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); # Insert more rows in node 1, to bump up the XID counter. Otherwise, if # rewind doesn't correctly rewind the changes made on the other node, @@ -135,10 +147,6 @@ $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('keep this')" $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this')"); $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this too')"); -# Also insert a row in 'bar' on node 3. It is unmodified in node 1, so it won't get -# overwritten by replaying the WAL from node 1. -$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); - # Wait for node 2 to catch up $node_2->poll_query_until('postgres', q|SELECT COUNT(*) > 1 FROM public.bar|, 't'); @@ -160,9 +168,10 @@ command_ok( [ 'pg_rewind', "--source-server=$node_1_connstr", - "--target-pgdata=$node_2_pgdata" + "--target-pgdata=$node_2_pgdata", + "--debug" ], - 'pg_rewind detects rewind needed'); + 'run pg_rewind'); # Now move back postgresql.conf with old settings move( @@ -174,7 +183,6 @@ $node_2->start; # Check contents of the test tables after rewind. The rows inserted in node 3 # before rewind should've been overwritten with the data from node 1. my $result; -$result = $node_2->safe_psql('postgres', 'checkpoint'); $result = $node_2->safe_psql('postgres', 'SELECT * FROM public.foo'); is($result, qq(keep this and this