From 2af6b4ad0f98769bed37e753cca23941839f3077 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Wed, 8 Oct 2025 19:49:53 +1100
Subject: [PATCH v2] log to say command is executing in dry run mode

---
 src/bin/pg_archivecleanup/pg_archivecleanup.c |  8 ++++++++
 src/bin/pg_basebackup/pg_createsubscriber.c   |  9 +++++++++
 src/bin/pg_combinebackup/pg_combinebackup.c   |  8 ++++++++
 src/bin/pg_resetwal/pg_resetwal.c             |  8 ++++++++
 src/bin/pg_resetwal/t/001_basic.pl            |  2 +-
 src/bin/pg_rewind/pg_rewind.c                 | 14 ++++++++++++--
 6 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index c25348b..dba1e74 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -375,6 +375,14 @@ main(int argc, char **argv)
 		exit(2);
 	}
 
+	if (dryrun)
+	{
+		pg_log_info("-----------------------------------------------------");
+		pg_log_info("pg_archivecleanup is executing in '--dry-run' mode.");
+		pg_log_info("No files will be removed.");
+		pg_log_info("-----------------------------------------------------");
+	}
+
 	/*
 	 * Check archive exists and other initialization if required.
 	 */
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 3986882..2e8972e 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -2273,6 +2273,15 @@ main(int argc, char **argv)
 		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
 		exit(1);
 	}
+
+	if (dry_run)
+	{
+		pg_log_info("-----------------------------------------------------");
+		pg_log_info("pg_createsubscriber is executing in '--dry-run' mode.");
+		pg_log_info("The target directory will not be modified.");
+		pg_log_info("-----------------------------------------------------");
+	}
+
 	pg_log_info("validating publisher connection string");
 	pub_base_conninfo = get_base_conninfo(opt.pub_conninfo_str,
 										  &dbname_conninfo);
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index f5cef99..7cbadb6 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -241,6 +241,14 @@ main(int argc, char *argv[])
 	if (opt.no_manifest)
 		opt.manifest_checksums = CHECKSUM_TYPE_NONE;
 
+	if (opt.dry_run)
+	{
+		pg_log_info("-----------------------------------------------------");
+		pg_log_info("pg_combinebackup is executing in '--dry-run' mode.");
+		pg_log_info("The target directory will not be modified.");
+		pg_log_info("-----------------------------------------------------");
+	}
+
 	/* Check that the platform supports the requested copy method. */
 	if (opt.copy_method == COPY_METHOD_CLONE)
 	{
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 7a4e4eb..83c22c1 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -396,6 +396,14 @@ main(int argc, char *argv[])
 		exit(1);
 	}
 
+	if (noupdate)
+	{
+		printf(_("-----------------------------------------------------"));
+		printf(_("pg_resetwal is executing in '--dry-run' mode."));
+		printf(_("Nothing will be modified."));
+		printf(_("-----------------------------------------------------"));
+	}
+
 	/*
 	 * Attempt to read the existing pg_control file
 	 */
diff --git a/src/bin/pg_resetwal/t/001_basic.pl b/src/bin/pg_resetwal/t/001_basic.pl
index d6bbbd0..247bd93 100644
--- a/src/bin/pg_resetwal/t/001_basic.pl
+++ b/src/bin/pg_resetwal/t/001_basic.pl
@@ -17,7 +17,7 @@ $node->init;
 $node->append_conf('postgresql.conf', 'track_commit_timestamp = on');
 
 command_like([ 'pg_resetwal', '-n', $node->data_dir ],
-	qr/checkpoint/, 'pg_resetwal -n produces output');
+	qr/checkpoint/m, 'pg_resetwal -n produces output');
 
 
 # Permissions on PGDATA should be default
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 0c68dd4..b5f4c6a 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -300,8 +300,18 @@ main(int argc, char **argv)
 	atexit(disconnect_atexit);
 
 	/*
-	 * Ok, we have all the options and we're ready to start. First, connect to
-	 * remote server.
+	 * Ok, we have all the options and we're ready to start.
+	 */
+	if (dry_run)
+	{
+		pg_log_info("-----------------------------------------------------");
+		pg_log_info("pg_rewind is executing in '--dry-run' mode.");
+		pg_log_info("The target directory will not be modified.");
+		pg_log_info("-----------------------------------------------------");
+	}
+
+	/*
+	 * First, connect to remote server.
 	 */
 	if (connstr_source)
 	{
-- 
1.8.3.1

