Hello Alena!

While reading through your patch, i noticed backend's include of
+#include "storage/fd.h"

which, as I understand, is needed for
+err = durable_rename(filename_with_original_contents, filename, ERROR);
+durable_rename(filename, filename_with_original_contents, FATAL);

Postgres' source code actually has two different durable_rename
signatures - one for frontend, and one for backend. As
pg_createsubscriber uses frontend definitions, I suggest replacing
this durable_rename with one from common/file_utils.h.

A patch with my approach to replacement is in attachments
(to be applied after yours).

p.s. I wonder why this builds at all - as far as I have tried, using
BE in FE usually leads to a ton of compilation errors or, at least,
warnings treated as errors - p.e, in this case backend definition
uses ereport(), which does not work in frontend utilities.

-- 
best regards,
Andrey Rudometov
From a61a4773d612df945e7169e738fc6ccd35eb76d9 Mon Sep 17 00:00:00 2001
From: Andrey Rudometov <[email protected]>
Date: Thu, 11 Dec 2025 12:13:11 +0700
Subject: [PATCH] Change createsubscriber's durable_rename to fe

---
 src/bin/pg_basebackup/pg_createsubscriber.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 85cfafbc069..ecb25747c3c 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -29,8 +29,7 @@
 #include "fe_utils/string_utils.h"
 #include "fe_utils/version.h"
 #include "getopt_long.h"
-#include "storage/fd.h"
-#include "utils/elog.h"
+#include "common/file_utils.h"
 
 #define	DEFAULT_SUB_PORT	"50432"
 #define	OBJECTTYPE_PUBLICATIONS  0x0001
@@ -200,7 +199,7 @@ cleanup_objects_atexit(void)
 			snprintf(filename_with_original_contents, MAXPGPATH,
 					 "%s" RECOVERY_CONF_PREFIX, filename);
 
-			err = durable_rename(filename_with_original_contents, filename, ERROR);
+			err = durable_rename(filename_with_original_contents, filename);
 		}
 		else					/* postgresql.auto.conf */
 		{
@@ -1345,11 +1344,14 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c
 		if (strcmp(recovery_conf_filename, "recovery.conf") == 0)
 		{
 			char		filename_with_original_contents[MAXPGPATH];
+			int			err = 0;
 
 			snprintf(filename_with_original_contents, MAXPGPATH,
 					 "%s" RECOVERY_CONF_PREFIX, filename);
 
-			durable_rename(filename, filename_with_original_contents, FATAL);
+			err = durable_rename(filename, filename_with_original_contents);
+			if (err)
+				pg_fatal("could not rename file \"%s\"", filename);
 		}
 
 		appendPQExpBuffer(recoveryconfcontents, "recovery_target_lsn = '%s'\n",
-- 
2.43.0

Reply via email to