Use USECS_PER_SEC from datatype/timestamp.h
authorÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 4 Nov 2025 09:07:54 +0000 (10:07 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 4 Nov 2025 09:07:54 +0000 (10:07 +0100)
We had two places defining their own constants for this.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/202510311750.mxiykx3tp4mx@alvherre.pgsql

src/bin/pg_basebackup/pg_createsubscriber.c
src/bin/pg_ctl/pg_ctl.c

index 61175453c90972eee744dfcad7d312664bc6819c..c1120d3643e7008d2df057598d3cb3dcbd6e196f 100644 (file)
@@ -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;
@@ -1604,8 +1604,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;
    }
 
index 8a405ff122c71474a68b343c60ff1b7a9d877904..4f666d91036b6e9fa2b0980a1c8853b92773cf32 100644 (file)
@@ -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,9 @@ 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
+StaticAssertDecl(USECS_PER_SEC % WAITS_PER_SEC == 0,
+                "WAITS_PER_SEC must divide USECS_PER_SEC evenly");
 
 static bool do_wait = true;
 static int wait_seconds = DEFAULT_WAIT;
@@ -699,7 +700,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 +739,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 +772,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 */
 }