From 37de60d9597d3dd4910d574edaf8c1fdeeef47f4 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Mon, 11 Nov 2024 21:03:54 +0200 Subject: [PATCH] Do not wallog AUX files at replica (#517) Co-authored-by: Konstantin Knizhnik --- src/backend/access/heap/rewriteheap.c | 5 +++++ src/backend/replication/logical/snapbuild.c | 22 +++++++++++++-------- src/backend/replication/slot.c | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 2597e52606f..c438ae14eed 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -759,6 +759,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/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index b20327efd52..55643dfa804 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1775,10 +1775,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); - LogLogicalMessage(prefix, (char *) ondisk, needed_length, false, true); - + /* 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); + LogLogicalMessage(prefix, (char *) ondisk, needed_length, false, true); + } errno = 0; pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE); if ((write(fd, ondisk, needed_length)) != needed_length) @@ -2141,10 +2144,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); - LogLogicalMessage(prefix, NULL, 0, false, true); - + /* 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); + LogLogicalMessage(prefix, NULL, 0, false, true); + } /* * It's not particularly harmful, though strange, if we can't * remove the file here. Don't prevent the checkpoint from diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index e904600aa21..fe9fbe410b9 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -899,7 +899,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]; @@ -2087,7 +2087,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];