From 28b88cfedf9a6028cf7ea32a80ea15a9bf971803 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sun, 18 May 2025 17:17:05 +0300 Subject: [PATCH 1/4] Do not perform recovery during replica promotion --- src/backend/access/transam/xlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b16fcf0086c..95cc92a373d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6065,7 +6065,7 @@ StartupXLOG(void) * In a normal crash recovery, we can just extend the timeline we were in. */ newTLI = endOfRecoveryInfo->lastRecTLI; - if (ArchiveRecoveryRequested) + if (ArchiveRecoveryRequested && !ZenithRecoveryRequested) { newTLI = findNewestTimeLine(recoveryTargetTLI) + 1; ereport(LOG, From 69613e831a6cf8b2d9e547ce39a583fa1b272994 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 29 May 2025 16:18:01 +0300 Subject: [PATCH 2/4] Handle CHECKPOINT_END_OF_RECOVERY in the same way as CHECKPOINT_IS_SHUTDOWN in CheckPointGuts --- src/backend/access/transam/xlog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 95cc92a373d..a9a672f475c 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7677,7 +7677,7 @@ CheckPointReplicationState(int flags) static void PreCheckPointGuts(int flags) { - if (flags & CHECKPOINT_IS_SHUTDOWN) + if (flags & (CHECKPOINT_IS_SHUTDOWN|CHECKPOINT_END_OF_RECOVERY)) { CheckPointReplicationState(flags); CheckPointBuffers(flags); @@ -7700,7 +7700,7 @@ PreCheckPointGuts(int flags) static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags) { - if (!(flags & CHECKPOINT_IS_SHUTDOWN)) + if (!(flags & (CHECKPOINT_IS_SHUTDOWN|CHECKPOINT_END_OF_RECOVERY))) CheckPointReplicationState(flags); /* Write out all dirty data in SLRUs and the main buffer pool */ From 32d704d965d8ad632c0ddef64b45a5ba95536442 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 29 May 2025 18:16:01 +0300 Subject: [PATCH 3/4] Handle CHECKPOINT_END_OF_RECOVERY in the same way as CHECKPOINT_IS_SHUTDOWN in CheckPointGuts --- src/backend/access/transam/xlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index a9a672f475c..7b8ef733f17 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7717,7 +7717,7 @@ CheckPointGuts(XLogRecPtr checkPointRedo, int flags) * Writing to the WAL during shutdown checkpoint cause Postgres panic. * So do it before in PreCheckPointGuts. */ - if (!(flags & CHECKPOINT_IS_SHUTDOWN)) + if (!(flags & (CHECKPOINT_IS_SHUTDOWN|CHECKPOINT_END_OF_RECOVERY))) CheckPointBuffers(flags); /* Perform all queued up fsyncs */ From db424d42d748f8ad91ac00e28db2c7f2efa42f7f Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Wed, 4 Jun 2025 16:25:10 +0300 Subject: [PATCH 4/4] Do not skip recovery in case of replica promotion --- src/backend/access/transam/xlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7b8ef733f17..e80fed8c067 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6065,7 +6065,7 @@ StartupXLOG(void) * In a normal crash recovery, we can just extend the timeline we were in. */ newTLI = endOfRecoveryInfo->lastRecTLI; - if (ArchiveRecoveryRequested && !ZenithRecoveryRequested) + if (ArchiveRecoveryRequested) { newTLI = findNewestTimeLine(recoveryTargetTLI) + 1; ereport(LOG,