Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 993d94c

Browse files
committed
Show a sensible value in pg_settings.unit for GUC_UNIT_XSEGS variables.
Commit 88e9823 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>
1 parent 190765a commit 993d94c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/backend/utils/misc/guc.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7998,20 +7998,23 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
79987998
/* unit */
79997999
if (conf->vartype == PGC_INT)
80008000
{
8001-
static char buf[8];
8002-
80038001
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
80048002
{
80058003
case GUC_UNIT_KB:
80068004
values[2] = "kB";
80078005
break;
80088006
case GUC_UNIT_BLOCKS:
8009-
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
8010-
values[2] = buf;
8007+
snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8008+
values[2] = pstrdup(buffer);
80118009
break;
80128010
case GUC_UNIT_XBLOCKS:
8013-
snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
8014-
values[2] = buf;
8011+
snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8012+
values[2] = pstrdup(buffer);
8013+
break;
8014+
case GUC_UNIT_XSEGS:
8015+
snprintf(buffer, sizeof(buffer), "%dMB",
8016+
XLOG_SEG_SIZE / (1024 * 1024));
8017+
values[2] = pstrdup(buffer);
80158018
break;
80168019
case GUC_UNIT_MS:
80178020
values[2] = "ms";
@@ -8022,7 +8025,12 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
80228025
case GUC_UNIT_MIN:
80238026
values[2] = "min";
80248027
break;
8028+
case 0:
8029+
values[2] = NULL;
8030+
break;
80258031
default:
8032+
elog(ERROR, "unrecognized GUC units value: %d",
8033+
conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
80268034
values[2] = NULL;
80278035
break;
80288036
}

src/include/utils/guc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ typedef enum
219219
#define GUC_UNIT_BLOCKS 0x2000 /* value is in blocks */
220220
#define GUC_UNIT_XBLOCKS 0x3000 /* value is in xlog blocks */
221221
#define GUC_UNIT_XSEGS 0x4000 /* value is in xlog segments */
222-
#define GUC_UNIT_MEMORY 0xF000 /* mask for KB, BLOCKS, XBLOCKS */
222+
#define GUC_UNIT_MEMORY 0xF000 /* mask for size-related units */
223223

224224
#define GUC_UNIT_MS 0x10000 /* value is in milliseconds */
225225
#define GUC_UNIT_S 0x20000 /* value is in seconds */
226226
#define GUC_UNIT_MIN 0x30000 /* value is in minutes */
227-
#define GUC_UNIT_TIME 0xF0000 /* mask for MS, S, MIN */
227+
#define GUC_UNIT_TIME 0xF0000 /* mask for time-related units */
228228

229229
#define GUC_UNIT (GUC_UNIT_MEMORY | GUC_UNIT_TIME)
230230

0 commit comments

Comments
 (0)