summaryrefslogtreecommitdiff
path: root/src/backend
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/backend
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 <aleksander@timescale.com> Discussion: https://www.postgresql.org/message-id/flat/9939aa8a-d7be-da2c-7715-0a0b5535a1f7@eisentraut.org
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/access/transam/xlog.c19
-rw-r--r--src/backend/bootstrap/bootstrap.c11
-rw-r--r--src/backend/utils/misc/guc_tables.c2
3 files changed, 18 insertions, 14 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 60c0b7ec3af..f6f8adc72a6 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1995,6 +1995,18 @@ assign_checkpoint_completion_target(double newval, void *extra)
CalculateCheckpointSegments();
}
+bool
+check_wal_segment_size(int *newval, void **extra, GucSource source)
+{
+ if (!IsValidWalSegSize(*newval))
+ {
+ GUC_check_errdetail("The WAL segment size must be a power of two between 1 MB and 1 GB.");
+ return false;
+ }
+
+ return true;
+}
+
/*
* At a checkpoint, how many WAL segments to recycle as preallocated future
* XLOG segments? Returns the highest segment that should be preallocated.
@@ -4145,10 +4157,11 @@ ReadControlFile(void)
if (!IsValidWalSegSize(wal_segment_size))
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg_plural("WAL segment size must be a power of two between 1 MB and 1 GB, but the control file specifies %d byte",
- "WAL segment size must be a power of two between 1 MB and 1 GB, but the control file specifies %d bytes",
+ errmsg_plural("invalid WAL segment size in control file (%d byte)",
+ "invalid WAL segment size in control file (%d bytes)",
wal_segment_size,
- wal_segment_size)));
+ wal_segment_size),
+ errdetail("The WAL segment size must be a power of two between 1 MB and 1 GB.")));
snprintf(wal_segsz_str, sizeof(wal_segsz_str), "%d", wal_segment_size);
SetConfigOption("wal_segment_size", wal_segsz_str, PGC_INTERNAL,
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 4cc2efa95c4..5810f8825e9 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -280,16 +280,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
strlcpy(OutputFileName, optarg, MAXPGPATH);
break;
case 'X':
- {
- int WalSegSz = strtoul(optarg, NULL, 0);
-
- if (!IsValidWalSegSize(WalSegSz))
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("-X requires a power of two value between 1 MB and 1 GB")));
- SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL,
- PGC_S_DYNAMIC_DEFAULT);
- }
+ SetConfigOption("wal_segment_size", optarg, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT);
break;
default:
write_stderr("Try \"%s --help\" for more information.\n",
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7e00dccb210..e0ca48a27d4 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -3166,7 +3166,7 @@ struct config_int ConfigureNamesInt[] =
DEFAULT_XLOG_SEG_SIZE,
WalSegMinSize,
WalSegMaxSize,
- NULL, NULL, NULL
+ check_wal_segment_size, NULL, NULL
},
{