postgres.git / summary / log / commit / refs
commit f50fa46cca9a1e5bfd517f7f1d979ef4db55ce03
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon Oct 03 20:40:06 2016 +0000
First released in: 10.0, 9.5.5, 9.6.1
Show a sensible value in pg_settings.unit for GUC_UNIT_XSEGS variables.
Commit 88e982302 invented GUC_UNIT_XSEGS for min_wal_size and max_wal_size,
but neglected to make it display sensibly in pg_settings.unit (by adding a
case to the switch in GetConfigOptionByNum). Fix that, and adjust said
switch to throw a run-time error the next time somebody forgets.
In passing, avoid using a static buffer for the output string --- the rest
of this function pstrdup's from a local buffer, and I see no very good
reason why the units code should do it differently and less safely.
Per report from Otar Shavadze. Back-patch to 9.5 where the new unit type
was added.
Report: <CAG-jOyA=iNFhN+yB4vfvqh688B7Tr5SArbYcFUAjZi=0Exp-Lg@mail.gmail.com>
src/backend/utils/misc/guc.c | 20 ++++++++++++++------
src/include/utils/guc.h | 4 ++--
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index f249b3906c3..9e6c5556228 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -7808,20 +7808,23 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
/* unit */
if (conf->vartype == PGC_INT)
{
- static char buf[8];
-
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
{
case GUC_UNIT_KB:
values[2] = "kB";
break;
case GUC_UNIT_BLOCKS:
- snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
- values[2] = buf;
+ snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
+ values[2] = pstrdup(buffer);
break;
case GUC_UNIT_XBLOCKS:
- snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
- values[2] = buf;
+ snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
+ values[2] = pstrdup(buffer);
+ break;
+ case GUC_UNIT_XSEGS:
+ snprintf(buffer, sizeof(buffer), "%dMB",
+ XLOG_SEG_SIZE / (1024 * 1024));
+ values[2] = pstrdup(buffer);
break;
case GUC_UNIT_MS:
values[2] = "ms";
@@ -7832,7 +7835,12 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
case GUC_UNIT_MIN:
values[2] = "min";
break;
+ case 0:
+ values[2] = NULL;
+ break;
default:
+ elog(ERROR, "unrecognized GUC units value: %d",
+ conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
values[2] = NULL;
break;
}
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 49ec3840af3..03a5dd1c573 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -219,12 +219,12 @@ typedef enum
#define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
#define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
#define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */
-#define GUC_UNIT_MEMORY 0xF000 /* mask for KB, BLOCKS, XBLOCKS */
+#define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
#define GUC_UNIT_MS 0x10000 /* value is in milliseconds */
#define GUC_UNIT_S 0x20000 /* value is in seconds */
#define GUC_UNIT_MIN 0x30000 /* value is in minutes */
-#define GUC_UNIT_TIME 0xF0000 /* mask for MS, S, MIN */
+#define GUC_UNIT_TIME 0xF0000 /* mask for time-related units */
#define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
[parent: 647a86e374d2]