Skip to content

Commit dc5bd38

Browse files
committed
Delay recovery mode LOG after reading backup_label and/or checkpoint record
When beginning recovery, a LOG is displayed by the startup process to show which recovery mode will be used depending on the .signal file(s) set in the data folder, like "standby mode", recovery up to a given target type and value, or archive recovery. A different patch is under discussion to simplify the startup code by requiring the presence of recovery.signal and/or standby.signal when a backup_label file is read. Delaying a bit this LOG ensures that the correct recovery mode would be reported, and putting it at this position does not make it lose its value. While on it, this commit adds a few comments documenting a bit more the initial recovery steps and their dependencies, and fixes an incorrect comment format. This introduces no behavior changes. Extracted from a larger patch by me. Reviewed-by: David Steele, Bowen Shi Discussion: https://postgr.es/m/ZArVOMifjzE7f8W7@paquier.xyz
1 parent c4ede4f commit dc5bd38

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

src/backend/access/transam/xlogrecovery.c

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static TimeLineID curFileTLI;
133133
* currently performing crash recovery using only XLOG files in pg_wal, but
134134
* will switch to using offline XLOG archives as soon as we reach the end of
135135
* WAL in pg_wal.
136-
*/
136+
*/
137137
bool ArchiveRecoveryRequested = false;
138138
bool InArchiveRecovery = false;
139139

@@ -540,42 +540,17 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
540540
readRecoverySignalFile();
541541
validateRecoveryParameters();
542542

543-
if (ArchiveRecoveryRequested)
544-
{
545-
if (StandbyModeRequested)
546-
ereport(LOG,
547-
(errmsg("entering standby mode")));
548-
else if (recoveryTarget == RECOVERY_TARGET_XID)
549-
ereport(LOG,
550-
(errmsg("starting point-in-time recovery to XID %u",
551-
recoveryTargetXid)));
552-
else if (recoveryTarget == RECOVERY_TARGET_TIME)
553-
ereport(LOG,
554-
(errmsg("starting point-in-time recovery to %s",
555-
timestamptz_to_str(recoveryTargetTime))));
556-
else if (recoveryTarget == RECOVERY_TARGET_NAME)
557-
ereport(LOG,
558-
(errmsg("starting point-in-time recovery to \"%s\"",
559-
recoveryTargetName)));
560-
else if (recoveryTarget == RECOVERY_TARGET_LSN)
561-
ereport(LOG,
562-
(errmsg("starting point-in-time recovery to WAL location (LSN) \"%X/%X\"",
563-
LSN_FORMAT_ARGS(recoveryTargetLSN))));
564-
else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE)
565-
ereport(LOG,
566-
(errmsg("starting point-in-time recovery to earliest consistent point")));
567-
else
568-
ereport(LOG,
569-
(errmsg("starting archive recovery")));
570-
}
571-
572543
/*
573544
* Take ownership of the wakeup latch if we're going to sleep during
574-
* recovery.
545+
* recovery, if required.
575546
*/
576547
if (ArchiveRecoveryRequested)
577548
OwnLatch(&XLogRecoveryCtl->recoveryWakeupLatch);
578549

550+
/*
551+
* Set the WAL reading processor now, as it will be needed when reading
552+
* the checkpoint record required (backup_label or not).
553+
*/
579554
private = palloc0(sizeof(XLogPageReadPrivate));
580555
xlogreader =
581556
XLogReaderAllocate(wal_segment_size, NULL,
@@ -609,6 +584,11 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
609584
replay_image_masked = (char *) palloc(BLCKSZ);
610585
primary_image_masked = (char *) palloc(BLCKSZ);
611586

587+
/*
588+
* Read the backup_label file. We want to run this part of the recovery
589+
* process after checking for signal files and after performing validation
590+
* of the recovery parameters.
591+
*/
612592
if (read_backup_label(&CheckPointLoc, &CheckPointTLI, &backupEndRequired,
613593
&backupFromStandby))
614594
{
@@ -705,6 +685,8 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
705685
}
706686
else
707687
{
688+
/* No backup_label file has been found if we are here. */
689+
708690
/*
709691
* If tablespace_map file is present without backup_label file, there
710692
* is no use of such file. There is no harm in retaining it, but it
@@ -788,6 +770,35 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
788770
wasShutdown = ((record->xl_info & ~XLR_INFO_MASK) == XLOG_CHECKPOINT_SHUTDOWN);
789771
}
790772

773+
if (ArchiveRecoveryRequested)
774+
{
775+
if (StandbyModeRequested)
776+
ereport(LOG,
777+
(errmsg("entering standby mode")));
778+
else if (recoveryTarget == RECOVERY_TARGET_XID)
779+
ereport(LOG,
780+
(errmsg("starting point-in-time recovery to XID %u",
781+
recoveryTargetXid)));
782+
else if (recoveryTarget == RECOVERY_TARGET_TIME)
783+
ereport(LOG,
784+
(errmsg("starting point-in-time recovery to %s",
785+
timestamptz_to_str(recoveryTargetTime))));
786+
else if (recoveryTarget == RECOVERY_TARGET_NAME)
787+
ereport(LOG,
788+
(errmsg("starting point-in-time recovery to \"%s\"",
789+
recoveryTargetName)));
790+
else if (recoveryTarget == RECOVERY_TARGET_LSN)
791+
ereport(LOG,
792+
(errmsg("starting point-in-time recovery to WAL location (LSN) \"%X/%X\"",
793+
LSN_FORMAT_ARGS(recoveryTargetLSN))));
794+
else if (recoveryTarget == RECOVERY_TARGET_IMMEDIATE)
795+
ereport(LOG,
796+
(errmsg("starting point-in-time recovery to earliest consistent point")));
797+
else
798+
ereport(LOG,
799+
(errmsg("starting archive recovery")));
800+
}
801+
791802
/*
792803
* If the location of the checkpoint record is not on the expected
793804
* timeline in the history of the requested timeline, we cannot proceed:

0 commit comments

Comments
 (0)