|
75 | 75 | #
|
76 | 76 | $node_1->stop('fast');
|
77 | 77 | $node_3->promote;
|
| 78 | +# Force a checkpoint after the promotion. pg_rewind looks at the control |
| 79 | +# file to determine what timeline the server is on, and that isn't updated |
| 80 | +# immediately at promotion, but only at the next checkpoint. When running |
| 81 | +# pg_rewind in remote mode, it's possible that we complete the test steps |
| 82 | +# after promotion so quickly that when pg_rewind runs, the standby has not |
| 83 | +# performed a checkpoint after promotion yet. |
| 84 | +$node_3->safe_psql('postgres', "checkpoint"); |
78 | 85 |
|
79 | 86 | # reconfigure node_1 as a standby following node_3
|
80 | 87 | my $node_3_connstr = $node_3->connstr;
|
|
105 | 112 | $node_3->wait_for_catchup('node_1', 'replay', $lsn);
|
106 | 113 |
|
107 | 114 | $node_1->promote;
|
| 115 | +# Force a checkpoint after promotion, like earlier. |
| 116 | +$node_1->safe_psql('postgres', "checkpoint"); |
108 | 117 |
|
109 | 118 | #
|
110 | 119 | # We now have a split-brain with two primaries. Insert a row on both to
|
111 | 120 | # demonstratively create a split brain. After the rewind, we should only
|
112 | 121 | # see the insert on 1, as the insert on node 3 is rewound away.
|
113 | 122 | #
|
114 | 123 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('keep this')");
|
| 124 | +# 'bar' is unmodified in node 1, so it won't be overwritten by replaying the |
| 125 | +# WAL from node 1. |
| 126 | +$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); |
115 | 127 |
|
116 | 128 | # Insert more rows in node 1, to bump up the XID counter. Otherwise, if
|
117 | 129 | # rewind doesn't correctly rewind the changes made on the other node,
|
|
120 | 132 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this')");
|
121 | 133 | $node_1->safe_psql('postgres', "INSERT INTO public.foo (t) VALUES ('and this too')");
|
122 | 134 |
|
123 |
| -# Also insert a row in 'bar' on node 3. It is unmodified in node 1, so it won't get |
124 |
| -# overwritten by replaying the WAL from node 1. |
125 |
| -$node_3->safe_psql('postgres', "INSERT INTO public.bar (t) VALUES ('rewind this')"); |
126 |
| - |
127 | 135 | # Wait for node 2 to catch up
|
128 | 136 | $node_2->poll_query_until('postgres',
|
129 | 137 | q|SELECT COUNT(*) > 1 FROM public.bar|, 't');
|
|
145 | 153 | [
|
146 | 154 | 'pg_rewind',
|
147 | 155 | "--source-server=$node_1_connstr",
|
148 |
| - "--target-pgdata=$node_2_pgdata" |
| 156 | + "--target-pgdata=$node_2_pgdata", |
| 157 | + "--debug" |
149 | 158 | ],
|
150 |
| - 'pg_rewind detects rewind needed'); |
| 159 | + 'run pg_rewind'); |
151 | 160 |
|
152 | 161 | # Now move back postgresql.conf with old settings
|
153 | 162 | move(
|
|
159 | 168 | # Check contents of the test tables after rewind. The rows inserted in node 3
|
160 | 169 | # before rewind should've been overwritten with the data from node 1.
|
161 | 170 | my $result;
|
162 |
| -$result = $node_2->safe_psql('postgres', 'checkpoint'); |
163 | 171 | $result = $node_2->safe_psql('postgres', 'SELECT * FROM public.foo');
|
164 | 172 | is($result, qq(keep this
|
165 | 173 | and this
|
|
0 commit comments