summaryrefslogtreecommitdiff
path: root/src/bin/initdb/initdb.c
diff options
context:
space:
mode:
authorPeter Eisentraut2023-08-28 13:15:20 +0000
committerPeter Eisentraut2023-08-28 13:17:04 +0000
commit36e4419d1f1ef06bba58a28a870aaaa8de73bb46 (patch)
tree9884e1cad81ae0aab5e7aba9f6d9bf676b8a7a3f /src/bin/initdb/initdb.c
parentbb9002257b2211c213ad5989446d83a61c6446d3 (diff)
Make error messages about WAL segment size more consistent
Make the primary messages more compact and make the detail messages uniform. In initdb.c and pg_resetwal.c, use the newish option_parse_int() to simplify some of the option parsing. For the backend GUC wal_segment_size, add a GUC check hook to do the verification instead of coding it in bootstrap.c. This might be overkill, but that way the check is in the right place and it becomes more self-documenting. In passing, make pg_controldata use the logging API for warning messages. Reviewed-by: Aleksander Alekseev <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/bin/initdb/initdb.c')
-rw-r--r--src/bin/initdb/initdb.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 3f4167682ab..c66467eb951 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -76,6 +76,7 @@
#include "common/restricted_token.h"
#include "common/string.h"
#include "common/username.h"
+#include "fe_utils/option_utils.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
#include "mb/pg_wchar.h"
@@ -163,8 +164,7 @@ static bool sync_only = false;
static bool show_setting = false;
static bool data_checksums = false;
static char *xlog_dir = NULL;
-static char *str_wal_segment_size_mb = NULL;
-static int wal_segment_size_mb;
+static int wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024);
/* internal vars */
@@ -3258,7 +3258,8 @@ main(int argc, char *argv[])
xlog_dir = pg_strdup(optarg);
break;
case 12:
- str_wal_segment_size_mb = pg_strdup(optarg);
+ if (!option_parse_int(optarg, "--wal-segsize", 1, 1024, &wal_segment_size_mb))
+ exit(1);
break;
case 13:
noinstructions = true;
@@ -3348,22 +3349,8 @@ main(int argc, char *argv[])
check_need_password(authmethodlocal, authmethodhost);
- /* set wal segment size */
- if (str_wal_segment_size_mb == NULL)
- wal_segment_size_mb = (DEFAULT_XLOG_SEG_SIZE) / (1024 * 1024);
- else
- {
- char *endptr;
-
- /* check that the argument is a number */
- wal_segment_size_mb = strtol(str_wal_segment_size_mb, &endptr, 10);
-
- /* verify that wal segment size is valid */
- if (endptr == str_wal_segment_size_mb || *endptr != '\0')
- pg_fatal("argument of --wal-segsize must be a number");
- if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
- pg_fatal("argument of --wal-segsize must be a power of 2 between 1 and 1024");
- }
+ if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
+ pg_fatal("argument of %s must be a power of 2 between 1 and 1024", "--wal-segsize");
get_restricted_token();