summaryrefslogtreecommitdiff
path: root/src/bin/initdb/initdb.c
diff options
context:
space:
mode:
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();