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

Commit f50fa46

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 647a86e commit f50fa46

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
@@ -7808,20 +7808,23 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
78087808
/* unit */
78097809
if (conf->vartype == PGC_INT)
78107810
{
7811-
static char buf[8];
7812-
78137811
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
78147812
{
78157813
case GUC_UNIT_KB:
78167814
values[2] = "kB";
78177815
break;
78187816
case GUC_UNIT_BLOCKS:
7819-
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
7820-
values[2] = buf;
7817+
snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
7818+
values[2] = pstrdup(buffer);
78217819
break;
78227820
case GUC_UNIT_XBLOCKS:
7823-
snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
7824-
values[2] = buf;
7821+
snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
7822+
values[2] = pstrdup(buffer);
7823+
break;
7824+
case GUC_UNIT_XSEGS:
7825+
snprintf(buffer, sizeof(buffer), "%dMB",
7826+
XLOG_SEG_SIZE / (1024 * 1024));
7827+
values[2] = pstrdup(buffer);
78257828
break;
78267829
case GUC_UNIT_MS:
78277830
values[2] = "ms";
@@ -7832,7 +7835,12 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
78327835
case GUC_UNIT_MIN:
78337836
values[2] = "min";
78347837
break;
7838+
case 0:
7839+
values[2] = NULL;
7840+
break;
78357841
default:
7842+
elog(ERROR, "unrecognized GUC units value: %d",
7843+
conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
78367844
values[2] = NULL;
78377845
break;
78387846
}

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)