Skip to content

Commit 6bc811c

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 814b9e9 commit 6bc811c

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
@@ -8016,20 +8016,23 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
80168016
/* unit */
80178017
if (conf->vartype == PGC_INT)
80188018
{
8019-
static char buf[8];
8020-
80218019
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
80228020
{
80238021
case GUC_UNIT_KB:
80248022
values[2] = "kB";
80258023
break;
80268024
case GUC_UNIT_BLOCKS:
8027-
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ / 1024);
8028-
values[2] = buf;
8025+
snprintf(buffer, sizeof(buffer), "%dkB", BLCKSZ / 1024);
8026+
values[2] = pstrdup(buffer);
80298027
break;
80308028
case GUC_UNIT_XBLOCKS:
8031-
snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ / 1024);
8032-
values[2] = buf;
8029+
snprintf(buffer, sizeof(buffer), "%dkB", XLOG_BLCKSZ / 1024);
8030+
values[2] = pstrdup(buffer);
8031+
break;
8032+
case GUC_UNIT_XSEGS:
8033+
snprintf(buffer, sizeof(buffer), "%dMB",
8034+
XLOG_SEG_SIZE / (1024 * 1024));
8035+
values[2] = pstrdup(buffer);
80338036
break;
80348037
case GUC_UNIT_MS:
80358038
values[2] = "ms";
@@ -8040,7 +8043,12 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
80408043
case GUC_UNIT_MIN:
80418044
values[2] = "min";
80428045
break;
8046+
case 0:
8047+
values[2] = NULL;
8048+
break;
80438049
default:
8050+
elog(ERROR, "unrecognized GUC units value: %d",
8051+
conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME));
80448052
values[2] = NULL;
80458053
break;
80468054
}

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy