@@ -840,69 +840,75 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
840
840
}
841
841
842
842
/*
843
- * Update pg_control to show that we are recovering and to show the
844
- * selected checkpoint as the place we are starting from. We also mark
845
- * pg_control with any minimum recovery stop point obtained from a backup
846
- * history file.
843
+ * If recovery is needed, update our in-memory copy of pg_control to show
844
+ * that we are recovering and to show the selected checkpoint as the place
845
+ * we are starting from. We also mark pg_control with any minimum recovery
846
+ * stop point obtained from a backup history file.
847
+ *
848
+ * We don't write the changes to disk yet, though. Only do that after
849
+ * initializing various subsystems.
847
850
*/
848
- if (InArchiveRecovery )
849
- {
850
- ControlFile -> state = DB_IN_ARCHIVE_RECOVERY ;
851
- }
852
- else
851
+ if (InRecovery )
853
852
{
854
- ereport (LOG ,
855
- (errmsg ("database system was not properly shut down; "
856
- "automatic recovery in progress" )));
857
- if (recoveryTargetTLI > ControlFile -> checkPointCopy .ThisTimeLineID )
853
+ if (InArchiveRecovery )
854
+ {
855
+ ControlFile -> state = DB_IN_ARCHIVE_RECOVERY ;
856
+ }
857
+ else
858
+ {
858
859
ereport (LOG ,
859
- (errmsg ("crash recovery starts in timeline %u "
860
- "and has target timeline %u" ,
861
- ControlFile -> checkPointCopy .ThisTimeLineID ,
862
- recoveryTargetTLI )));
863
- ControlFile -> state = DB_IN_CRASH_RECOVERY ;
864
- }
865
- ControlFile -> checkPoint = CheckPointLoc ;
866
- ControlFile -> checkPointCopy = checkPoint ;
867
- if (InArchiveRecovery )
868
- {
869
- /* initialize minRecoveryPoint if not set yet */
870
- if (ControlFile -> minRecoveryPoint < checkPoint .redo )
860
+ (errmsg ("database system was not properly shut down; "
861
+ "automatic recovery in progress" )));
862
+ if (recoveryTargetTLI > ControlFile -> checkPointCopy .ThisTimeLineID )
863
+ ereport (LOG ,
864
+ (errmsg ("crash recovery starts in timeline %u "
865
+ "and has target timeline %u" ,
866
+ ControlFile -> checkPointCopy .ThisTimeLineID ,
867
+ recoveryTargetTLI )));
868
+ ControlFile -> state = DB_IN_CRASH_RECOVERY ;
869
+ }
870
+ ControlFile -> checkPoint = CheckPointLoc ;
871
+ ControlFile -> checkPointCopy = checkPoint ;
872
+ if (InArchiveRecovery )
871
873
{
872
- ControlFile -> minRecoveryPoint = checkPoint .redo ;
873
- ControlFile -> minRecoveryPointTLI = checkPoint .ThisTimeLineID ;
874
+ /* initialize minRecoveryPoint if not set yet */
875
+ if (ControlFile -> minRecoveryPoint < checkPoint .redo )
876
+ {
877
+ ControlFile -> minRecoveryPoint = checkPoint .redo ;
878
+ ControlFile -> minRecoveryPointTLI = checkPoint .ThisTimeLineID ;
879
+ }
874
880
}
875
- }
876
-
877
- /*
878
- * Set backupStartPoint if we're starting recovery from a base backup.
879
- *
880
- * Also set backupEndPoint and use minRecoveryPoint as the backup end
881
- * location if we're starting recovery from a base backup which was taken
882
- * from a standby. In this case, the database system status in pg_control
883
- * must indicate that the database was already in recovery. Usually that
884
- * will be DB_IN_ARCHIVE_RECOVERY but also can be
885
- * DB_SHUTDOWNED_IN_RECOVERY if recovery previously was interrupted before
886
- * reaching this point; e.g. because restore_command or primary_conninfo
887
- * were faulty.
888
- *
889
- * Any other state indicates that the backup somehow became corrupted and
890
- * we can't sensibly continue with recovery.
891
- */
892
- if (haveBackupLabel )
893
- {
894
- ControlFile -> backupStartPoint = checkPoint .redo ;
895
- ControlFile -> backupEndRequired = backupEndRequired ;
896
881
897
- if (backupFromStandby )
882
+ /*
883
+ * Set backupStartPoint if we're starting recovery from a base backup.
884
+ *
885
+ * Also set backupEndPoint and use minRecoveryPoint as the backup end
886
+ * location if we're starting recovery from a base backup which was
887
+ * taken from a standby. In this case, the database system status in
888
+ * pg_control must indicate that the database was already in recovery.
889
+ * Usually that will be DB_IN_ARCHIVE_RECOVERY but also can be
890
+ * DB_SHUTDOWNED_IN_RECOVERY if recovery previously was interrupted
891
+ * before reaching this point; e.g. because restore_command or
892
+ * primary_conninfo were faulty.
893
+ *
894
+ * Any other state indicates that the backup somehow became corrupted
895
+ * and we can't sensibly continue with recovery.
896
+ */
897
+ if (haveBackupLabel )
898
898
{
899
- if (dbstate_at_startup != DB_IN_ARCHIVE_RECOVERY &&
900
- dbstate_at_startup != DB_SHUTDOWNED_IN_RECOVERY )
901
- ereport (FATAL ,
902
- (errmsg ("backup_label contains data inconsistent with control file" ),
903
- errhint ("This means that the backup is corrupted and you will "
904
- "have to use another backup for recovery." )));
905
- ControlFile -> backupEndPoint = ControlFile -> minRecoveryPoint ;
899
+ ControlFile -> backupStartPoint = checkPoint .redo ;
900
+ ControlFile -> backupEndRequired = backupEndRequired ;
901
+
902
+ if (backupFromStandby )
903
+ {
904
+ if (dbstate_at_startup != DB_IN_ARCHIVE_RECOVERY &&
905
+ dbstate_at_startup != DB_SHUTDOWNED_IN_RECOVERY )
906
+ ereport (FATAL ,
907
+ (errmsg ("backup_label contains data inconsistent with control file" ),
908
+ errhint ("This means that the backup is corrupted and you will "
909
+ "have to use another backup for recovery." )));
910
+ ControlFile -> backupEndPoint = ControlFile -> minRecoveryPoint ;
911
+ }
906
912
}
907
913
}
908
914
0 commit comments