Skip to content

Commit 6b34e55

Browse files
committed
pg_rewind: Don't error if the two clusters are already on the same timeline
This previously resulted in an error and a nonzero exit status, but after discussion this should rather be a noop with a zero exit status.
1 parent 8c16155 commit 6b34e55

File tree

2 files changed

+46
-27
lines changed

2 files changed

+46
-27
lines changed

src/bin/pg_rewind/pg_rewind.c

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -216,41 +216,46 @@ main(int argc, char **argv)
216216
* do.
217217
*/
218218
if (ControlFile_target.checkPointCopy.ThisTimeLineID == ControlFile_source.checkPointCopy.ThisTimeLineID)
219-
pg_fatal("source and target cluster are on the same timeline\n");
220-
221-
findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);
222-
printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),
223-
(uint32) (divergerec >> 32), (uint32) divergerec,
224-
targetHistory[lastcommontliIndex].tli);
225-
226-
/*
227-
* Check for the possibility that the target is in fact a direct ancestor
228-
* of the source. In that case, there is no divergent history in the
229-
* target that needs rewinding.
230-
*/
231-
if (ControlFile_target.checkPoint >= divergerec)
232219
{
233-
rewind_needed = true;
220+
printf(_("source and target cluster are on the same timeline\n"));
221+
rewind_needed = false;
234222
}
235223
else
236224
{
237-
XLogRecPtr chkptendrec;
238-
239-
/* Read the checkpoint record on the target to see where it ends. */
240-
chkptendrec = readOneRecord(datadir_target,
241-
ControlFile_target.checkPoint,
242-
targetNentries - 1);
225+
findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);
226+
printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),
227+
(uint32) (divergerec >> 32), (uint32) divergerec,
228+
targetHistory[lastcommontliIndex].tli);
243229

244230
/*
245-
* If the histories diverged exactly at the end of the shutdown
246-
* checkpoint record on the target, there are no WAL records in the
247-
* target that don't belong in the source's history, and no rewind is
248-
* needed.
231+
* Check for the possibility that the target is in fact a direct ancestor
232+
* of the source. In that case, there is no divergent history in the
233+
* target that needs rewinding.
249234
*/
250-
if (chkptendrec == divergerec)
251-
rewind_needed = false;
252-
else
235+
if (ControlFile_target.checkPoint >= divergerec)
236+
{
253237
rewind_needed = true;
238+
}
239+
else
240+
{
241+
XLogRecPtr chkptendrec;
242+
243+
/* Read the checkpoint record on the target to see where it ends. */
244+
chkptendrec = readOneRecord(datadir_target,
245+
ControlFile_target.checkPoint,
246+
targetNentries - 1);
247+
248+
/*
249+
* If the histories diverged exactly at the end of the shutdown
250+
* checkpoint record on the target, there are no WAL records in the
251+
* target that don't belong in the source's history, and no rewind is
252+
* needed.
253+
*/
254+
if (chkptendrec == divergerec)
255+
rewind_needed = false;
256+
else
257+
rewind_needed = true;
258+
}
254259
}
255260

256261
if (!rewind_needed)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 1;
5+
6+
use RewindTest;
7+
8+
# Test that running pg_rewind if the two clusters are on the same
9+
# timeline runs successfully.
10+
11+
RewindTest::setup_cluster();
12+
RewindTest::start_master();
13+
RewindTest::create_standby();
14+
RewindTest::run_pg_rewind('local');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy