From 3d6896afaa89c05b693e9a29275001b801b8b479 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sun, 25 May 2025 08:50:20 +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 0d257d1fd55..a863138c3c1 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5689,7 +5689,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 3da009ed1a80fe57c5feb521e41a5d017affeb78 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 29 May 2025 16:17:50 +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 a863138c3c1..167b70fed9b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7220,7 +7220,7 @@ CheckPointReplicationState(void) static void PreCheckPointGuts(int flags) { - if (flags & CHECKPOINT_IS_SHUTDOWN) + if (flags & (CHECKPOINT_IS_SHUTDOWN|CHECKPOINT_END_OF_RECOVERY)) { CheckPointReplicationState(); CheckPointBuffers(flags); @@ -7243,7 +7243,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(); /* Write out all dirty data in SLRUs and the main buffer pool */ From 77c63bfebff5c833682cc2654e2191fec4d5b24e Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 29 May 2025 18:15:49 +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 167b70fed9b..feadec9c5d6 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7260,7 +7260,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 7a4c0eacaeb9b97416542fa19103061c166460b1 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Wed, 4 Jun 2025 16:24:03 +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 feadec9c5d6..fb88d2b69d5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5689,7 +5689,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,