Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b06d8e5

Browse filesBrowse files
committed
Accept "B" in all memory-unit GUCs, and improve error messages.
Commit 6e7baa3 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
1 parent e41c2b0 commit b06d8e5
Copy full SHA for b06d8e5

File tree

Expand file treeCollapse file tree

1 file changed

+12
-2
lines changed
Filter options
  • src/backend/utils/misc
Expand file treeCollapse file tree

1 file changed

+12
-2
lines changed

‎src/backend/utils/misc/guc.c

Copy file name to clipboardExpand all lines: src/backend/utils/misc/guc.c
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ typedef struct
705705
char unit[MAX_UNIT_LEN + 1]; /* unit, as a string, like "kB" or
706706
* "min" */
707707
int base_unit; /* GUC_UNIT_XXX */
708-
int multiplier; /* If positive, multiply the value with this
708+
int64 multiplier; /* If positive, multiply the value with this
709709
* for unit -> base_unit conversion. If
710710
* negative, divide (with the absolute value) */
711711
} unit_conversion;
@@ -718,10 +718,16 @@ typedef struct
718718
#error XLOG_BLCKSZ must be between 1KB and 1MB
719719
#endif
720720

721-
static const char *memory_units_hint = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
721+
static const char *memory_units_hint = gettext_noop("Valid units for this parameter are \"B\", \"kB\", \"MB\", \"GB\", and \"TB\".");
722722

723723
static const unit_conversion memory_unit_conversion_table[] =
724724
{
725+
/*
726+
* TB -> bytes conversion always overflows 32-bit integer, so this always
727+
* produces an error. Include it nevertheless for completeness, and so
728+
* that you get an "out of range" error, rather than "invalid unit".
729+
*/
730+
{"TB", GUC_UNIT_BYTE, INT64CONST(1024) * 1024 * 1024 * 1024},
725731
{"GB", GUC_UNIT_BYTE, 1024 * 1024 * 1024},
726732
{"MB", GUC_UNIT_BYTE, 1024 * 1024},
727733
{"kB", GUC_UNIT_BYTE, 1024},
@@ -731,21 +737,25 @@ static const unit_conversion memory_unit_conversion_table[] =
731737
{"GB", GUC_UNIT_KB, 1024 * 1024},
732738
{"MB", GUC_UNIT_KB, 1024},
733739
{"kB", GUC_UNIT_KB, 1},
740+
{"B", GUC_UNIT_KB, -1024},
734741

735742
{"TB", GUC_UNIT_MB, 1024 * 1024},
736743
{"GB", GUC_UNIT_MB, 1024},
737744
{"MB", GUC_UNIT_MB, 1},
738745
{"kB", GUC_UNIT_MB, -1024},
746+
{"B", GUC_UNIT_MB, -(1024 * 1024)},
739747

740748
{"TB", GUC_UNIT_BLOCKS, (1024 * 1024 * 1024) / (BLCKSZ / 1024)},
741749
{"GB", GUC_UNIT_BLOCKS, (1024 * 1024) / (BLCKSZ / 1024)},
742750
{"MB", GUC_UNIT_BLOCKS, 1024 / (BLCKSZ / 1024)},
743751
{"kB", GUC_UNIT_BLOCKS, -(BLCKSZ / 1024)},
752+
{"B", GUC_UNIT_BLOCKS, -BLCKSZ},
744753

745754
{"TB", GUC_UNIT_XBLOCKS, (1024 * 1024 * 1024) / (XLOG_BLCKSZ / 1024)},
746755
{"GB", GUC_UNIT_XBLOCKS, (1024 * 1024) / (XLOG_BLCKSZ / 1024)},
747756
{"MB", GUC_UNIT_XBLOCKS, 1024 / (XLOG_BLCKSZ / 1024)},
748757
{"kB", GUC_UNIT_XBLOCKS, -(XLOG_BLCKSZ / 1024)},
758+
{"B", GUC_UNIT_XBLOCKS, -XLOG_BLCKSZ},
749759

750760
{""} /* end of table marker */
751761
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.