summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2018-05-23 07:02:40 +0000
committerHeikki Linnakangas2018-05-23 07:22:26 +0000
commitb06d8e58b5ac257c2119312c47c4a0f233c5e0ca (patch)
tree89c67c6bfef99412dce2f94007f434d0a7d088fb
parente41c2b057f92c3824ffe0157e83ee43624487035 (diff)
Accept "B" in all memory-unit GUCs, and improve error messages.
Commit 6e7baa3227 added support for "B" unit, for specifying config options in bytes. However, it was only accepted in GUC_UNIT_BYTE settings, wal_segment_size and track_activity_query_size, and not e.g. in work_mem. This patch makes it consistent, so that "B" accepted in all the same contexts where "kB", "MB", and so forth are accepted. Add "B" to the list of accepted units in the error hint, along with "kB", "MB", etc. Add an entry in the conversion table for "TB" to "B" conversion. A terabyte is out of range for any GUC_UNIT_BYTE option, so you always get an "out of range" error with that, but without it, you get a confusing error message that claims that "TB" is not an accepted unit, with a hint that nevertheless lists "TB" as an accepted unit. Reviewed-by: Alexander Korotkov, Andres Freund Discussion: https://www.postgresql.org/message-id/1bfe7f4a-7e22-aa6e-7b37-f4d222ed2d67@iki.fi
-rw-r--r--src/backend/utils/misc/guc.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 7cd2d2d80ef..ee1444c427f 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -705,7 +705,7 @@ typedef struct
char unit[MAX_UNIT_LEN + 1]; /* unit, as a string, like "kB" or
* "min" */
int base_unit; /* GUC_UNIT_XXX */
- int multiplier; /* If positive, multiply the value with this
+ int64 multiplier; /* If positive, multiply the value with this
* for unit -> base_unit conversion. If
* negative, divide (with the absolute value) */
} unit_conversion;
@@ -718,10 +718,16 @@ typedef struct
#error XLOG_BLCKSZ must be between 1KB and 1MB
#endif
-static const char *memory_units_hint = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
+static const char *memory_units_hint = gettext_noop("Valid units for this parameter are \"B\", \"kB\", \"MB\", \"GB\", and \"TB\".");
static const unit_conversion memory_unit_conversion_table[] =
{
+ /*
+ * TB -> bytes conversion always overflows 32-bit integer, so this always
+ * produces an error. Include it nevertheless for completeness, and so
+ * that you get an "out of range" error, rather than "invalid unit".
+ */
+ {"TB", GUC_UNIT_BYTE, INT64CONST(1024) * 1024 * 1024 * 1024},
{"GB", GUC_UNIT_BYTE, 1024 * 1024 * 1024},
{"MB", GUC_UNIT_BYTE, 1024 * 1024},
{"kB", GUC_UNIT_BYTE, 1024},
@@ -731,21 +737,25 @@ static const unit_conversion memory_unit_conversion_table[] =
{"GB", GUC_UNIT_KB, 1024 * 1024},
{"MB", GUC_UNIT_KB, 1024},
{"kB", GUC_UNIT_KB, 1},
+ {"B", GUC_UNIT_KB, -1024},
{"TB", GUC_UNIT_MB, 1024 * 1024},
{"GB", GUC_UNIT_MB, 1024},
{"MB", GUC_UNIT_MB, 1},
{"kB", GUC_UNIT_MB, -1024},
+ {"B", GUC_UNIT_MB, -(1024 * 1024)},
{"TB", GUC_UNIT_BLOCKS, (1024 * 1024 * 1024) / (BLCKSZ / 1024)},
{"GB", GUC_UNIT_BLOCKS, (1024 * 1024) / (BLCKSZ / 1024)},
{"MB", GUC_UNIT_BLOCKS, 1024 / (BLCKSZ / 1024)},
{"kB", GUC_UNIT_BLOCKS, -(BLCKSZ / 1024)},
+ {"B", GUC_UNIT_BLOCKS, -BLCKSZ},
{"TB", GUC_UNIT_XBLOCKS, (1024 * 1024 * 1024) / (XLOG_BLCKSZ / 1024)},
{"GB", GUC_UNIT_XBLOCKS, (1024 * 1024) / (XLOG_BLCKSZ / 1024)},
{"MB", GUC_UNIT_XBLOCKS, 1024 / (XLOG_BLCKSZ / 1024)},
{"kB", GUC_UNIT_XBLOCKS, -(XLOG_BLCKSZ / 1024)},
+ {"B", GUC_UNIT_XBLOCKS, -XLOG_BLCKSZ},
{""} /* end of table marker */
};