From e3cb06f6712323debc9553e79955501437948794 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Fri, 31 Dec 2021 05:52:24 +0000
Subject: [PATCH v1] Skip processing snapshot, mapping files during
 end-of-recovery checkpoint

This makes the server available faster. However the regular
checkpoints can process these files.
---
 src/backend/access/transam/xlog.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 87cd05c945..9d1331dd0d 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -9570,8 +9570,21 @@ CheckPointGuts(XLogRecPtr checkPointRedo, int flags)
 {
 	CheckPointRelationMap();
 	CheckPointReplicationSlots();
-	CheckPointSnapBuild();
-	CheckPointLogicalRewriteHeap();
+
+	/*
+	 * Let's not process snapshot and mapping files during end-of-recovery
+	 * checkpoint to make the server available faster. However, the regular
+	 * checkpoints can process these files.
+	 */
+	if (flags & CHECKPOINT_END_OF_RECOVERY)
+		ereport((log_checkpoints ? LOG : DEBUG2),
+				(errmsg("skipped processing of replication slot snapshot and mapping files during end-of-recovery checkpoint")));
+	else
+	{
+		CheckPointSnapBuild();
+		CheckPointLogicalRewriteHeap();
+	}
+
 	CheckPointReplicationOrigin();
 
 	/* Write out all dirty data in SLRUs and the main buffer pool */
-- 
2.25.1

