@@ -212,40 +212,45 @@ main(int argc, char **argv)
212
212
* do.
213
213
*/
214
214
if (ControlFile_target .checkPointCopy .ThisTimeLineID == ControlFile_source .checkPointCopy .ThisTimeLineID )
215
- pg_fatal ("source and target cluster are on the same timeline\n" );
216
-
217
- findCommonAncestorTimeline (& divergerec ,& lastcommontli );
218
- printf (_ ("servers diverged at WAL position %X/%X on timeline %u\n" ),
219
- (uint32 ) (divergerec >>32 ), (uint32 )divergerec ,lastcommontli );
220
-
221
- /*
222
- * Check for the possibility that the target is in fact a direct ancestor
223
- * of the source. In that case, there is no divergent history in the
224
- * target that needs rewinding.
225
- */
226
- if (ControlFile_target .checkPoint >=divergerec )
227
215
{
228
- rewind_needed = true;
216
+ printf (_ ("source and target cluster are on the same timeline\n" ));
217
+ rewind_needed = false;
229
218
}
230
219
else
231
220
{
232
- XLogRecPtr chkptendrec ;
233
-
234
- /* Read the checkpoint record on the target to see where it ends. */
235
- chkptendrec = readOneRecord (datadir_target ,
236
- ControlFile_target .checkPoint ,
237
- ControlFile_target .checkPointCopy .ThisTimeLineID );
221
+ findCommonAncestorTimeline (& divergerec ,& lastcommontli );
222
+ printf (_ ("servers diverged at WAL position %X/%X on timeline %u\n" ),
223
+ (uint32 ) (divergerec >>32 ), (uint32 )divergerec ,lastcommontli );
238
224
239
225
/*
240
- * If the histories diverged exactly at the end of the shutdown
241
- * checkpoint record on the target, there are no WAL records in the
242
- * target that don't belong in the source's history, and no rewind is
243
- * needed.
226
+ * Check for the possibility that the target is in fact a direct ancestor
227
+ * of the source. In that case, there is no divergent history in the
228
+ * target that needs rewinding.
244
229
*/
245
- if (chkptendrec == divergerec )
246
- rewind_needed = false;
247
- else
230
+ if (ControlFile_target .checkPoint >=divergerec )
231
+ {
248
232
rewind_needed = true;
233
+ }
234
+ else
235
+ {
236
+ XLogRecPtr chkptendrec ;
237
+
238
+ /* Read the checkpoint record on the target to see where it ends. */
239
+ chkptendrec = readOneRecord (datadir_target ,
240
+ ControlFile_target .checkPoint ,
241
+ ControlFile_target .checkPointCopy .ThisTimeLineID );
242
+
243
+ /*
244
+ * If the histories diverged exactly at the end of the shutdown
245
+ * checkpoint record on the target, there are no WAL records in the
246
+ * target that don't belong in the source's history, and no rewind is
247
+ * needed.
248
+ */
249
+ if (chkptendrec == divergerec )
250
+ rewind_needed = false;
251
+ else
252
+ rewind_needed = true;
253
+ }
249
254
}
250
255
251
256
if (!rewind_needed )
@@ -374,18 +379,21 @@ sanityChecks(void)
374
379
/*
375
380
* Target cluster better not be running. This doesn't guard against
376
381
* someone starting the cluster concurrently. Also, this is probably more
377
- * strict than necessary; it's OK if themaster was not shut down cleanly,
378
- * as long as it isn't running at the moment.
382
+ * strict than necessary; it's OK if thetarget node was not shut down
383
+ *cleanly, as long as it isn't running at the moment.
379
384
*/
380
- if (ControlFile_target .state != DB_SHUTDOWNED )
385
+ if (ControlFile_target .state != DB_SHUTDOWNED &&
386
+ ControlFile_target .state != DB_SHUTDOWNED_IN_RECOVERY )
381
387
pg_fatal ("target server must be shut down cleanly\n" );
382
388
383
389
/*
384
390
* When the source is a data directory, also require that the source
385
391
* server is shut down. There isn't any very strong reason for this
386
392
* limitation, but better safe than sorry.
387
393
*/
388
- if (datadir_source && ControlFile_source .state != DB_SHUTDOWNED )
394
+ if (datadir_source &&
395
+ ControlFile_source .state != DB_SHUTDOWNED &&
396
+ ControlFile_source .state != DB_SHUTDOWNED_IN_RECOVERY )
389
397
pg_fatal ("source data directory must be shut down cleanly\n" );
390
398
}
391
399