|
80 | 80 | #
|
81 | 81 | $node_1->stop('fast');
|
82 | 82 | $node_3->promote;
|
| 83 | +# Force a checkpoint after the promotion. pg_rewind looks at the control |
| 84 | +# file to determine what timeline the server is on, and that isn't updated |
| 85 | +# immediately at promotion, but only at the next checkpoint. When running |
| 86 | +# pg_rewind in remote mode, it's possible that we complete the test steps |
| 87 | +# after promotion so quickly that when pg_rewind runs, the standby has not |
| 88 | +# performed a checkpoint after promotion yet. |
| 89 | +$node_3->safe_psql('postgres', "checkpoint"); |
83 | 90 |
|
84 | 91 | # reconfigure node_1 as a standby following node_3
|
85 | 92 | rmtree $node_1->data_dir;
|
|
116 | 123 | or die "Timed out while waiting for standby to catch up";
|
117 | 124 |
|
118 | 125 | $node_1->promote;
|
| 126 | +# Force a checkpoint after promotion, like earlier. |
| 127 | +$node_1->safe_psql('postgres', "checkpoint"); |
119 | 128 |
|
120 | 129 | # Wait until nodes 1 and 3 have been fully promoted.
|
121 | 130 | $node_1->poll_query_until('postgres', "SELECT pg_is_in_recovery() <> true");
|
|
127 | 136 | # see the insert on 1, as the insert on node 3 is rewound away.
|
128 | 137 | #
|
129 | 138 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('keep this')");
|
| 139 | +# 'bar' is unmodified in node 1, so it won't be overwritten by replaying the |
| 140 | +# WAL from node 1. |
| 141 | +$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); |
130 | 142 |
|
131 | 143 | # Insert more rows in node 1, to bump up the XID counter. Otherwise, if
|
132 | 144 | # rewind doesn't correctly rewind the changes made on the other node,
|
|
135 | 147 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this')");
|
136 | 148 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this too')");
|
137 | 149 |
|
138 |
| -# Also insert a row in 'bar' on node 3. It is unmodified in node 1, so it won't get |
139 |
| -# overwritten by replaying the WAL from node 1. |
140 |
| -$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); |
141 |
| - |
142 | 150 | # Wait for node 2 to catch up
|
143 | 151 | $node_2->poll_query_until('postgres',
|
144 | 152 | q|SELECT COUNT(*) > 1 FROM public.bar|, 't');
|
|
160 | 168 | [
|
161 | 169 | 'pg_rewind',
|
162 | 170 | "--source-server=$node_1_connstr",
|
163 |
| - "--target-pgdata=$node_2_pgdata" |
| 171 | + "--target-pgdata=$node_2_pgdata", |
| 172 | + "--debug" |
164 | 173 | ],
|
165 |
| - 'pg_rewind detects rewind needed'); |
| 174 | + 'run pg_rewind'); |
166 | 175 |
|
167 | 176 | # Now move back postgresql.conf with old settings
|
168 | 177 | move(
|
|
174 | 183 | # Check contents of the test tables after rewind. The rows inserted in node 3
|
175 | 184 | # before rewind should've been overwritten with the data from node 1.
|
176 | 185 | my $result;
|
177 |
| -$result = $node_2->safe_psql('postgres', 'checkpoint'); |
178 | 186 | $result = $node_2->safe_psql('postgres', 'SELECT * FROM public.foo');
|
179 | 187 | is($result, qq(keep this
|
180 | 188 | and this
|
|
0 commit comments