Subject: [PATCH 1/2] pg_ctl: use USECS_PER_SEC from datatype/timestamp.h instead of reinventing the wheel

From: Álvaro Herrera <[email-masked]>
Date: Fri, 31 Oct 2025 16:51:22 +0100

---
 src/bin/pg_basebackup/pg_createsubscriber.c |  5 ++---
 src/bin/pg_ctl/pg_ctl.c                     | 12 ++++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index f59c293d875..52e7c9212a2 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -23,6 +23,7 @@
 #include "common/logging.h"
 #include "common/pg_prng.h"
 #include "common/restricted_token.h"
+#include "datatype/timestamp.h"
 #include "fe_utils/recovery_gen.h"
 #include "fe_utils/simple_list.h"
 #include "fe_utils/string_utils.h"
@@ -129,7 +130,6 @@ static void drop_existing_subscription(PGconn *conn, const char *subname,
 static void get_publisher_databases(struct CreateSubscriberOptions *opt,
 									bool dbnamespecified);
 
-#define	USEC_PER_SEC	1000000
 #define	WAIT_INTERVAL	1		/* 1 second */
 
 static const char *progname;
@@ -1610,8 +1610,7 @@ wait_for_end_recovery(const char *conninfo, const struct CreateSubscriberOptions
 		}
 
 		/* Keep waiting */
-		pg_usleep(WAIT_INTERVAL * USEC_PER_SEC);
-
+		pg_usleep(WAIT_INTERVAL * USECS_PER_SEC);
 		timer += WAIT_INTERVAL;
 	}
 
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 8a405ff122c..b270c0c0d82 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -26,6 +26,7 @@
 #include "common/file_perm.h"
 #include "common/logging.h"
 #include "common/string.h"
+#include "datatype/timestamp.h"
 #include "getopt_long.h"
 #include "utils/pidfile.h"
 
@@ -68,9 +69,7 @@ typedef enum
 
 #define DEFAULT_WAIT	60
 
-#define USEC_PER_SEC	1000000
-
-#define WAITS_PER_SEC	10		/* should divide USEC_PER_SEC evenly */
+#define WAITS_PER_SEC	10		/* should divide USECS_PER_SEC evenly */
 
 static bool do_wait = true;
 static int	wait_seconds = DEFAULT_WAIT;
@@ -594,6 +593,7 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint)
 {
 	int			i;
 
+	static_assert(USECS_PER_SEC % WAITS_PER_SEC == 0);
 	for (i = 0; i < wait_seconds * WAITS_PER_SEC; i++)
 	{
 		char	  **optlines;
@@ -699,7 +699,7 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint)
 				print_msg(".");
 		}
 
-		pg_usleep(USEC_PER_SEC / WAITS_PER_SEC);
+		pg_usleep(USECS_PER_SEC / WAITS_PER_SEC);
 	}
 
 	/* out of patience; report that postmaster is still starting up */
@@ -738,7 +738,7 @@ wait_for_postmaster_stop(void)
 
 		if (cnt % WAITS_PER_SEC == 0)
 			print_msg(".");
-		pg_usleep(USEC_PER_SEC / WAITS_PER_SEC);
+		pg_usleep(USECS_PER_SEC / WAITS_PER_SEC);
 	}
 	return false;				/* timeout reached */
 }
@@ -771,7 +771,7 @@ wait_for_postmaster_promote(void)
 
 		if (cnt % WAITS_PER_SEC == 0)
 			print_msg(".");
-		pg_usleep(USEC_PER_SEC / WAITS_PER_SEC);
+		pg_usleep(USECS_PER_SEC / WAITS_PER_SEC);
 	}
 	return false;				/* timeout reached */
 }
-- 
2.47.3

--iqvkb7rmsfgsymxy
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment;
	filename="0002-Remove-WaitPMResult-enum-in-pg_createsubscriber.patch"