From: Simon Riggs Date: Sun, 19 May 2013 16:31:07 +0000 (+0100) Subject: Init crash recovery using the latest available TLI X-Git-Tag: REL9_3_BETA2~83 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4337a0dcbd29e5b11c2157f808916de62de05e4;p=postgresql Init crash recovery using the latest available TLI This simplifies the handling of crashes after fast promotion and various minor cases that can exist in short timing windows around that case. Broad fix to bug reported by Michael Paquier on -hackers, approach prompted by Heikki Linnakangas --- diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ceb20b7917..7d34218bef 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -4932,10 +4932,14 @@ StartupXLOG(void) RelationCacheInitFileRemove(); /* - * Initialize on the assumption we want to recover to the same timeline + * Initialize on the assumption we want to recover to the latest timeline * that's active according to pg_control. */ - recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID; + if (ControlFile->minRecoveryPointTLI > + ControlFile->checkPointCopy.ThisTimeLineID) + recoveryTargetTLI = ControlFile->minRecoveryPointTLI; + else + recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID; /* * Check for recovery control file, and if so set up state for offline @@ -4972,22 +4976,6 @@ StartupXLOG(void) ereport(LOG, (errmsg("starting archive recovery"))); } - else if (ControlFile->minRecoveryPointTLI > 0) - { - /* - * If the minRecoveryPointTLI is set when not in Archive Recovery - * it means that we have crashed after ending recovery and - * yet before we wrote a new checkpoint on the new timeline. - * That means we are doing a crash recovery that needs to cross - * timelines to get to our newly assigned timeline again. - * The timeline we are headed for is exact and not 'latest'. - * As soon as we hit a checkpoint, the minRecoveryPointTLI is - * reset, so we will not enter crash recovery again. - */ - Assert(ControlFile->minRecoveryPointTLI != 1); - recoveryTargetTLI = ControlFile->minRecoveryPointTLI; - recoveryTargetIsLatest = false; - } /* * Take ownership of the wakeup latch if we're going to sleep during