Skip to content

Commit bab54e3

Browse files
committed
Support TB (terabyte) memory unit in GUC variables.
Patch by Simon Riggs, reviewed by Jeff Janes and me.
1 parent f979599 commit bab54e3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

doc/src/sgml/config.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
For convenience,
4040
a different unit can also be specified explicitly. Valid memory units
4141
are <literal>kB</literal> (kilobytes), <literal>MB</literal>
42-
(megabytes), and <literal>GB</literal> (gigabytes); valid time units
42+
(megabytes), <literal>GB</literal> (gigabytes), and <literal>TB</literal> (terabytes); valid time units
4343
are <literal>ms</literal> (milliseconds), <literal>s</literal>
4444
(seconds), <literal>min</literal> (minutes), <literal>h</literal>
4545
(hours), and <literal>d</literal> (days). Note that the multiplier

src/backend/utils/misc/guc.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105

106106
#define KB_PER_MB (1024)
107107
#define KB_PER_GB (1024*1024)
108+
#define KB_PER_TB (1024*1024*1024)
108109

109110
#define MS_PER_S 1000
110111
#define S_PER_MIN 60
@@ -4837,7 +4838,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
48374838
{
48384839
/* Set hint for use if no match or trailing garbage */
48394840
if (hintmsg)
4840-
*hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", and \"GB\".");
4841+
*hintmsg = gettext_noop("Valid units for this parameter are \"kB\", \"MB\", \"GB\", and \"TB\".");
48414842

48424843
#if BLCKSZ < 1024 || BLCKSZ > (1024*1024)
48434844
#error BLCKSZ must be between 1KB and 1MB
@@ -4891,6 +4892,22 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
48914892
break;
48924893
}
48934894
}
4895+
else if (strncmp(endptr, "TB", 2) == 0)
4896+
{
4897+
endptr += 2;
4898+
switch (flags & GUC_UNIT_MEMORY)
4899+
{
4900+
case GUC_UNIT_KB:
4901+
val *= KB_PER_TB;
4902+
break;
4903+
case GUC_UNIT_BLOCKS:
4904+
val *= KB_PER_TB / (BLCKSZ / 1024);
4905+
break;
4906+
case GUC_UNIT_XBLOCKS:
4907+
val *= KB_PER_TB / (XLOG_BLCKSZ / 1024);
4908+
break;
4909+
}
4910+
}
48944911
}
48954912
else if (flags & GUC_UNIT_TIME)
48964913
{
@@ -7384,7 +7401,12 @@ _ShowOption(struct config_generic * record, bool use_units)
73847401
break;
73857402
}
73867403

7387-
if (result % KB_PER_GB == 0)
7404+
if (result % KB_PER_TB == 0)
7405+
{
7406+
result /= KB_PER_TB;
7407+
unit = "TB";
7408+
}
7409+
else if (result % KB_PER_GB == 0)
73887410
{
73897411
result /= KB_PER_GB;
73907412
unit = "GB";

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Memory units: kB = kilobytes Time units: ms = milliseconds
2828
# MB = megabytes s = seconds
2929
# GB = gigabytes min = minutes
30-
# h = hours
30+
# TB = terabytes h = hours
3131
# d = days
3232

3333

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