From d80e55942a096d9f1ab10b84ab6f2a9d371cf88d Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sat, 18 Nov 2023 13:27:17 -0800 Subject: [PATCH v2] WIP: Log when starting up from a base backup Author: Reviewed-by: Discussion: https://postgr.es/m/20231117041811.vz4vgkthwjnwp2pp@awork3.anarazel.de Backpatch: --- src/backend/access/transam/xlogrecovery.c | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index c61566666aa..9803b481118 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -603,6 +603,22 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, if (StandbyModeRequested) EnableStandbyMode(); + /* + * Omitting backup_label when creating a new replica, PITR node etc. + * unfortunately is a common cause of corruption. Logging that + * backup_label was used makes it a bit easier to exclude that as the + * cause of observed corruption. + * + * Do so before we try to read the checkpoint record (which can fail), + * as otherwise it can be hard to understand why a checkpoint other + * than ControlFile->checkPoint is used. + */ + ereport(LOG, + (errmsg("starting recovery from base backup with redo LSN %X/%X, checkpoint LSN %X/%X, on timeline ID %u", + LSN_FORMAT_ARGS(RedoStartLSN), + LSN_FORMAT_ARGS(CheckPointLoc), + CheckPointTLI))); + /* * When a backup_label file is present, we want to roll forward from * the checkpoint it identifies, rather than using pg_control. @@ -742,6 +758,16 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, EnableStandbyMode(); } + /* + * For the same reason as when starting up with backup_label present, + * emit a log message when we continue initializing from a base + * backup. + */ + if (ControlFile->backupStartPoint != InvalidXLogRecPtr) + ereport(LOG, + (errmsg("restarting recovery from base backup with redo LSN %X/%X", + LSN_FORMAT_ARGS(ControlFile->backupStartPoint)))); + /* Get the last valid checkpoint record. */ CheckPointLoc = ControlFile->checkPoint; CheckPointTLI = ControlFile->checkPointCopy.ThisTimeLineID; @@ -2151,6 +2177,8 @@ CheckRecoveryConsistency(void) if (!XLogRecPtrIsInvalid(backupEndPoint) && backupEndPoint <= lastReplayedEndRecPtr) { + XLogRecPtr oldBackupStartPoint = backupStartPoint; + elog(DEBUG1, "end of backup reached"); /* @@ -2161,6 +2189,10 @@ CheckRecoveryConsistency(void) backupStartPoint = InvalidXLogRecPtr; backupEndPoint = InvalidXLogRecPtr; backupEndRequired = false; + + ereport(LOG, + (errmsg("completed recovery from base backup with redo LSN %X/%X", + LSN_FORMAT_ARGS(oldBackupStartPoint)))); } /* -- 2.38.0