diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-10-03 16:40:06 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-10-03 16:40:26 -0400 |
commit | 993d94c59038fb80068a2b7780a1062dcaa2bb4f (patch) | |
tree | 9ccf8e08145cf9619feb0e225d8f018cb1e9291f /src | |
parent | 190765a059cc5e8226cdb18b9715741b32b12255 (diff) | |
download | postgresql-993d94c59038fb80068a2b7780a1062dcaa2bb4f.tar.gz postgresql-993d94c59038fb80068a2b7780a1062dcaa2bb4f.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/misc/guc.c | 20 | ||||
-rw-r--r-- | 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 bc9d33f6ff1..2414b2f1c9a 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -7998,20 +7998,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"; @@ -8022,7 +8025,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 e1de1a5d065..0bf9f210678 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) |