mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-04 16:57:18 +02:00
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>
This commit is contained in:
parent
647a86e374
commit
f50fa46cca
@ -7808,20 +7808,23 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
|
|||||||
/* unit */
|
/* unit */
|
||||||
if (conf->vartype == PGC_INT)
|
if (conf->vartype == PGC_INT)
|
||||||
{
|
{
|
||||||
static char buf[8];
|
|
||||||
|
|
||||||
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
|
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
|
||||||
{
|
{
|
||||||
case GUC_UNIT_KB:
|
case GUC_UNIT_KB:
|
||||||
values[2] = "kB";
|
values[2] = "kB";
|
||||||
break;
|
break;
|
||||||
case GUC_UNIT_BLOCKS:
|
case GUC_UNIT_BLOCKS:
|
||||||
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
|
snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
|
||||||
values[2] = buf;
|
values[2] = pstrdup(buffer);
|
||||||
break;
|
break;
|
||||||
case GUC_UNIT_XBLOCKS:
|
case GUC_UNIT_XBLOCKS:
|
||||||
snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
|
snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
|
||||||
values[2] = buf;
|
values[2] = pstrdup(buffer);
|
||||||
|
break;
|
||||||
|
case GUC_UNIT_XSEGS:
|
||||||
|
snprintf(buffer, sizeof(buffer), "%dMB",
|
||||||
|
XLOG_SEG_SIZE / (1024 * 1024));
|
||||||
|
values[2] = pstrdup(buffer);
|
||||||
break;
|
break;
|
||||||
case GUC_UNIT_MS:
|
case GUC_UNIT_MS:
|
||||||
values[2] = "ms";
|
values[2] = "ms";
|
||||||
@ -7832,7 +7835,12 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
|
|||||||
case GUC_UNIT_MIN:
|
case GUC_UNIT_MIN:
|
||||||
values[2] = "min";
|
values[2] = "min";
|
||||||
break;
|
break;
|
||||||
|
case 0:
|
||||||
|
values[2] = NULL;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
elog(ERROR, "unrecognized GUC units value: %d",
|
||||||
|
conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
|
||||||
values[2] = NULL;
|
values[2] = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -219,12 +219,12 @@ typedef enum
|
|||||||
#define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
|
#define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
|
||||||
#define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
|
#define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
|
||||||
#define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */
|
#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_MS 0x10000 /* value is in milliseconds */
|
||||||
#define GUC_UNIT_S 0x20000 /* value is in seconds */
|
#define GUC_UNIT_S 0x20000 /* value is in seconds */
|
||||||
#define GUC_UNIT_MIN 0x30000 /* value is in minutes */
|
#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)
|
#define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user