mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -216,41 +216,46 @@ main(int argc, char **argv)
|
|||||||
* do.
|
* do.
|
||||||
*/
|
*/
|
||||||
if (ControlFile_target.checkPointCopy.ThisTimeLineID == ControlFile_source.checkPointCopy.ThisTimeLineID)
|
if (ControlFile_target.checkPointCopy.ThisTimeLineID == ControlFile_source.checkPointCopy.ThisTimeLineID)
|
||||||
pg_fatal("source and target cluster are on the same timeline\n");
|
|
||||||
|
|
||||||
findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);
|
|
||||||
printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),
|
|
||||||
(uint32) (divergerec >> 32), (uint32) divergerec,
|
|
||||||
targetHistory[lastcommontliIndex].tli);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check for the possibility that the target is in fact a direct ancestor
|
|
||||||
* of the source. In that case, there is no divergent history in the
|
|
||||||
* target that needs rewinding.
|
|
||||||
*/
|
|
||||||
if (ControlFile_target.checkPoint >= divergerec)
|
|
||||||
{
|
{
|
||||||
rewind_needed = true;
|
printf(_("source and target cluster are on the same timeline\n"));
|
||||||
|
rewind_needed = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
XLogRecPtr chkptendrec;
|
findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);
|
||||||
|
printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),
|
||||||
/* Read the checkpoint record on the target to see where it ends. */
|
(uint32) (divergerec >> 32), (uint32) divergerec,
|
||||||
chkptendrec = readOneRecord(datadir_target,
|
targetHistory[lastcommontliIndex].tli);
|
||||||
ControlFile_target.checkPoint,
|
|
||||||
targetNentries - 1);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the histories diverged exactly at the end of the shutdown
|
* Check for the possibility that the target is in fact a direct ancestor
|
||||||
* checkpoint record on the target, there are no WAL records in the
|
* of the source. In that case, there is no divergent history in the
|
||||||
* target that don't belong in the source's history, and no rewind is
|
* target that needs rewinding.
|
||||||
* needed.
|
|
||||||
*/
|
*/
|
||||||
if (chkptendrec == divergerec)
|
if (ControlFile_target.checkPoint >= divergerec)
|
||||||
rewind_needed = false;
|
{
|
||||||
else
|
|
||||||
rewind_needed = true;
|
rewind_needed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
XLogRecPtr chkptendrec;
|
||||||
|
|
||||||
|
/* Read the checkpoint record on the target to see where it ends. */
|
||||||
|
chkptendrec = readOneRecord(datadir_target,
|
||||||
|
ControlFile_target.checkPoint,
|
||||||
|
targetNentries - 1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the histories diverged exactly at the end of the shutdown
|
||||||
|
* checkpoint record on the target, there are no WAL records in the
|
||||||
|
* target that don't belong in the source's history, and no rewind is
|
||||||
|
* needed.
|
||||||
|
*/
|
||||||
|
if (chkptendrec == divergerec)
|
||||||
|
rewind_needed = false;
|
||||||
|
else
|
||||||
|
rewind_needed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rewind_needed)
|
if (!rewind_needed)
|
||||||
|
14
src/bin/pg_rewind/t/005_same_timeline.pl
Normal file
14
src/bin/pg_rewind/t/005_same_timeline.pl
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use TestLib;
|
||||||
|
use Test::More tests => 1;
|
||||||
|
|
||||||
|
use RewindTest;
|
||||||
|
|
||||||
|
# Test that running pg_rewind if the two clusters are on the same
|
||||||
|
# timeline runs successfully.
|
||||||
|
|
||||||
|
RewindTest::setup_cluster();
|
||||||
|
RewindTest::start_master();
|
||||||
|
RewindTest::create_standby();
|
||||||
|
RewindTest::run_pg_rewind('local');
|
Reference in New Issue
Block a user