From 8fc2cdeaef347fc235febe68628aceb7449bd7dd Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sat, 19 Oct 2024 08:57:52 +0300 Subject: [PATCH 1/2] Do not wallog AUX files at replica --- src/backend/access/heap/rewriteheap.c | 5 +++++ src/backend/replication/slot.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 15cd48850b0..f75de64c72a 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -792,6 +792,11 @@ static void wallog_mapping_file(char const* path, int fd) { char prefix[MAXPGPATH]; + + /* Do not wallog AUX file at replica */ + if (!XLogInsertAllowed()) + return; + snprintf(prefix, sizeof(prefix), "neon-file:%s", path); if (fd < 0) { diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 8490b22718d..13c2e0aac4a 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -686,7 +686,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot) sprintf(path, "pg_replslot/%s", NameStr(slot->data.name)); sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name)); - if (SlotIsLogical(slot)) + if (SlotIsLogical(slot) && XLogInsertAllowed()) { /* NEON specific: delete slot from storage using logical message */ char prefix[MAXPGPATH]; @@ -1832,7 +1832,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) ReplicationSlotOnDiskChecksummedSize); FIN_CRC32C(cp.checksum); - if (SlotIsLogical(slot) && cp.slotdata.restart_lsn != InvalidXLogRecPtr) + if (SlotIsLogical(slot) && XLogInsertAllowed() && cp.slotdata.restart_lsn != InvalidXLogRecPtr) { /* NEON specific: persist slot in storage using logical message */ char prefix[MAXPGPATH]; From ab3d5dfcc1ca2ec2c801bc1142cb54472690c781 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sat, 19 Oct 2024 08:58:45 +0300 Subject: [PATCH 2/2] Do not wallog AUX files at replica --- src/backend/replication/logical/snapbuild.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index ce27f018b4d..f19260dc1f0 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1763,9 +1763,13 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn) (errcode_for_file_access(), errmsg("could not open file \"%s\": %m", tmppath))); - /* NEON specific: persist snapshot in storage using logical message */ - snprintf(prefix, sizeof(prefix), "neon-file:%s", path); - XLogFlush(LogLogicalMessage(prefix, (char*)ondisk, needed_length, false)); + /* Do not wallog AUX file at replica */ + if (XLogInsertAllowed()) + { + /* NEON specific: persist snapshot in storage using logical message */ + snprintf(prefix, sizeof(prefix), "neon-file:%s", path); + XLogFlush(LogLogicalMessage(prefix, (char*)ondisk, needed_length, false)); + } errno = 0; pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE); @@ -2129,9 +2133,13 @@ CheckPointSnapBuild(void) { elog(DEBUG1, "removing snapbuild snapshot %s", path); - /* NEON specific: delete file from storage using logical message */ - snprintf(prefix, sizeof(prefix), "neon-file:%s", path); - XLogFlush(LogLogicalMessage(prefix, NULL, 0, false)); + /* Do not wallog AUX file at replica */ + if (XLogInsertAllowed()) + { + /* NEON specific: delete file from storage using logical message */ + snprintf(prefix, sizeof(prefix), "neon-file:%s", path); + XLogFlush(LogLogicalMessage(prefix, NULL, 0, false)); + } /* * It's not particularly harmful, though strange, if we can't