Skip to content

Commit 5441a64

Browse files
committed
The attached patch changes units of the some default values in
postgresql.conf. - shared_buffers = 32000kB => 32MB - temp_buffers = 8000kB => 8MB - wal_buffers = 8 => 64kB The code of initdb was a bit modified to write MB-unit values. Values greater than 8000kB are rounded out to MB. GUC_UNIT_XBLOCKS is added for wal_buffers. It is like GUC_UNIT_BLOCKS, but uses XLOG_BLCKSZ instead of BLCKSZ. Also, I cleaned up the test of GUC_UNIT_* flags in preparation to add more unit flags in less bits. ITAGAKI Takahiro
1 parent e15ce61 commit 5441a64

File tree

4 files changed

+99
-46
lines changed

4 files changed

+99
-46
lines changed

src/backend/utils/misc/guc.c

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.352 2006/09/22 21:39:57 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.353 2006/10/03 21:11:54 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -1149,7 +1149,7 @@ static struct config_int ConfigureNamesInt[] =
11491149
GUC_UNIT_BLOCKS
11501150
},
11511151
&NBuffers,
1152-
1000, 16, INT_MAX / 2, NULL, NULL
1152+
1024, 16, INT_MAX / 2, NULL, NULL
11531153
},
11541154

11551155
{
@@ -1159,7 +1159,7 @@ static struct config_int ConfigureNamesInt[] =
11591159
GUC_UNIT_BLOCKS
11601160
},
11611161
&num_temp_buffers,
1162-
1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
1162+
1024, 100, INT_MAX / 2, NULL, show_num_temp_buffers
11631163
},
11641164

11651165
{
@@ -1414,7 +1414,8 @@ static struct config_int ConfigureNamesInt[] =
14141414
{
14151415
{"wal_buffers", PGC_POSTMASTER, WAL_SETTINGS,
14161416
gettext_noop("Sets the number of disk-page buffers in shared memory for WAL."),
1417-
NULL
1417+
NULL,
1418+
GUC_UNIT_XBLOCKS
14181419
},
14191420
&XLOGbuffers,
14201421
8, 4, INT_MAX, NULL, NULL
@@ -3606,8 +3607,18 @@ parse_int(const char *value, int *result, int flags)
36063607
endptr += 2;
36073608
}
36083609

3609-
if (used && (flags & GUC_UNIT_BLOCKS))
3610-
val /= (BLCKSZ/1024);
3610+
if (used)
3611+
{
3612+
switch (flags & GUC_UNIT_MEMORY)
3613+
{
3614+
case GUC_UNIT_BLOCKS:
3615+
val /= (BLCKSZ/1024);
3616+
break;
3617+
case GUC_UNIT_XBLOCKS:
3618+
val /= (XLOG_BLCKSZ/1024);
3619+
break;
3620+
}
3621+
}
36113622
}
36123623

36133624
if ((flags & GUC_UNIT_TIME) && endptr != value)
@@ -3647,10 +3658,18 @@ parse_int(const char *value, int *result, int flags)
36473658
endptr += 1;
36483659
}
36493660

3650-
if (used && (flags & GUC_UNIT_S))
3651-
val /= MS_PER_S;
3652-
else if (used && (flags & GUC_UNIT_MIN))
3653-
val /= MS_PER_MIN;
3661+
if (used)
3662+
{
3663+
switch (flags & GUC_UNIT_TIME)
3664+
{
3665+
case GUC_UNIT_S:
3666+
val /= MS_PER_S;
3667+
break;
3668+
case GUC_UNIT_MIN:
3669+
val /= MS_PER_MIN;
3670+
break;
3671+
}
3672+
}
36543673
}
36553674

36563675
if (endptr == value || *endptr != '\0' || errno == ERANGE
@@ -4961,23 +4980,34 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
49614980
/* unit */
49624981
if (conf->vartype == PGC_INT)
49634982
{
4964-
if (conf->flags & GUC_UNIT_KB)
4965-
values[2] = "kB";
4966-
else if (conf->flags & GUC_UNIT_BLOCKS)
4967-
{
4968-
static char buf[8];
4983+
static char buf[8];
49694984

4970-
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ/1024);
4971-
values[2] = buf;
4985+
switch (conf->flags & (GUC_UNIT_MEMORY | GUC_UNIT_TIME))
4986+
{
4987+
case GUC_UNIT_KB:
4988+
values[2] = "kB";
4989+
break;
4990+
case GUC_UNIT_BLOCKS:
4991+
snprintf(buf, sizeof(buf), "%dkB", BLCKSZ/1024);
4992+
values[2] = buf;
4993+
break;
4994+
case GUC_UNIT_XBLOCKS:
4995+
snprintf(buf, sizeof(buf), "%dkB", XLOG_BLCKSZ/1024);
4996+
values[2] = buf;
4997+
break;
4998+
case GUC_UNIT_MS:
4999+
values[2] = "ms";
5000+
break;
5001+
case GUC_UNIT_S:
5002+
values[2] = "s";
5003+
break;
5004+
case GUC_UNIT_MIN:
5005+
values[2] = "min";
5006+
break;
5007+
default:
5008+
values[2] = "";
5009+
break;
49725010
}
4973-
else if (conf->flags & GUC_UNIT_MS)
4974-
values[2] = "ms";
4975-
else if (conf->flags & GUC_UNIT_S)
4976-
values[2] = "s";
4977-
else if (conf->flags & GUC_UNIT_MIN)
4978-
values[2] = "min";
4979-
else
4980-
values[2] = "";
49815011
}
49825012
else
49835013
values[2] = NULL;
@@ -5246,8 +5276,15 @@ _ShowOption(struct config_generic * record, bool use_units)
52465276

52475277
if (use_units && result > 0 && (record->flags & GUC_UNIT_MEMORY))
52485278
{
5249-
if (record->flags & GUC_UNIT_BLOCKS)
5250-
result *= BLCKSZ/1024;
5279+
switch (record->flags & GUC_UNIT_MEMORY)
5280+
{
5281+
case GUC_UNIT_BLOCKS:
5282+
result *= BLCKSZ/1024;
5283+
break;
5284+
case GUC_UNIT_XBLOCKS:
5285+
result *= XLOG_BLCKSZ/1024;
5286+
break;
5287+
}
52515288

52525289
if (result % KB_PER_GB == 0)
52535290
{
@@ -5266,10 +5303,15 @@ _ShowOption(struct config_generic * record, bool use_units)
52665303
}
52675304
else if (use_units && result > 0 && (record->flags & GUC_UNIT_TIME))
52685305
{
5269-
if (record->flags & GUC_UNIT_S)
5270-
result = result * MS_PER_S;
5271-
else if (record->flags & GUC_UNIT_MIN)
5272-
result = result * MS_PER_MIN;
5306+
switch (record->flags & GUC_UNIT_TIME)
5307+
{
5308+
case GUC_UNIT_S:
5309+
result *= MS_PER_S;
5310+
break;
5311+
case GUC_UNIT_MIN:
5312+
result *= MS_PER_MIN;
5313+
break;
5314+
}
52735315

52745316
if (result % MS_PER_D == 0)
52755317
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898

9999
# - Memory -
100100

101-
#shared_buffers = 32000kB # min 128kB or max_connections*16kB
101+
#shared_buffers = 32MB # min 128kB or max_connections*16kB
102102
# (change requires restart)
103-
#temp_buffers = 8000kB # min 800kB
103+
#temp_buffers = 8MB # min 800kB
104104
#max_prepared_transactions = 5 # can be 0 or more
105105
# (change requires restart)
106106
# Note: increasing max_prepared_transactions costs ~600 bytes of shared memory
@@ -111,7 +111,7 @@
111111

112112
# - Free Space Map -
113113

114-
#max_fsm_pages = 1600000 # min max_fsm_relations*16, 6 bytes each
114+
#max_fsm_pages = 1638400 # min max_fsm_relations*16, 6 bytes each
115115
# (change requires restart)
116116
#max_fsm_relations = 1000 # min 100, ~70 bytes each
117117
# (change requires restart)
@@ -154,7 +154,7 @@
154154
# fsync_writethrough
155155
# open_sync
156156
#full_page_writes = on # recover from partial page writes
157-
#wal_buffers = 8 # min 4, 8kB each
157+
#wal_buffers = 64kB # min 4, 8kB each
158158
# (change requires restart)
159159
#commit_delay = 0 # range 0-100000, in microseconds
160160
#commit_siblings = 5 # range 1-1000

src/bin/initdb/initdb.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.122 2006/09/14 23:21:47 momjian Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.123 2006/10/03 21:11:55 momjian Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1113,10 +1113,14 @@ test_config_settings(void)
11131113
static const int trial_conns[] = {
11141114
100, 50, 40, 30, 20, 10
11151115
};
1116+
1117+
/*
1118+
* Candidate values for shared_buffers in kB. When the value is
1119+
* divisible by 1024, we write it in MB-unit to configuration files.
1120+
*/
11161121
static const int trial_bufs[] = {
1117-
32000, 28000, 24000, 20000, 16000, 12000,
1118-
8000, 7200, 6400, 5600, 4800, 4000,
1119-
3200, 2400, 1600, 800, 400
1122+
32768, 28672, 24576, 20480, 16384, 12288,
1123+
8192, 7200, 6400, 5600, 4800, 4000,
11201124
};
11211125

11221126
char cmd[MAXPGPATH];
@@ -1190,7 +1194,10 @@ test_config_settings(void)
11901194
n_buffers = test_buffs;
11911195
n_fsm_pages = FSM_FOR_BUFS(n_buffers);
11921196

1193-
printf("%dkB/%d\n", n_buffers, n_fsm_pages);
1197+
if (n_buffers % 1024 == 0)
1198+
printf("%dMB/%d\n", n_buffers/1024, n_fsm_pages);
1199+
else
1200+
printf("%dkB/%d\n", n_buffers, n_fsm_pages);
11941201
}
11951202

11961203
/*
@@ -1213,11 +1220,14 @@ setup_config(void)
12131220
snprintf(repltok, sizeof(repltok), "max_connections = %d", n_connections);
12141221
conflines = replace_token(conflines, "#max_connections = 100", repltok);
12151222

1216-
snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB", n_buffers);
1217-
conflines = replace_token(conflines, "#shared_buffers = 32000kB", repltok);
1223+
if (n_buffers % 1024 == 0)
1224+
snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB", n_buffers/1024);
1225+
else
1226+
snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB", n_buffers);
1227+
conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
12181228

12191229
snprintf(repltok, sizeof(repltok), "max_fsm_pages = %d", n_fsm_pages);
1220-
conflines = replace_token(conflines, "#max_fsm_pages = 1600000", repltok);
1230+
conflines = replace_token(conflines, "#max_fsm_pages = 1638400", repltok);
12211231

12221232
#if DEF_PGPORT != 5432
12231233
snprintf(repltok, sizeof(repltok), "#port = %d", DEF_PGPORT);

src/include/utils/guc_tables.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.28 2006/08/14 02:27:27 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc_tables.h,v 1.29 2006/10/03 21:11:55 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -132,12 +132,13 @@ struct config_generic
132132

133133
#define GUC_UNIT_KB 0x0400 /* value is in 1 kB */
134134
#define GUC_UNIT_BLOCKS 0x0800 /* value is in blocks */
135-
#define GUC_UNIT_MEMORY (GUC_UNIT_KB|GUC_UNIT_BLOCKS)
135+
#define GUC_UNIT_XBLOCKS 0x0C00 /* value is in xlog blocks */
136+
#define GUC_UNIT_MEMORY 0x0C00 /* mask for KB, BLOCKS, XBLOCKS */
136137

137138
#define GUC_UNIT_MS 0x1000 /* value is in milliseconds */
138139
#define GUC_UNIT_S 0x2000 /* value is in seconds */
139140
#define GUC_UNIT_MIN 0x4000 /* value is in minutes */
140-
#define GUC_UNIT_TIME (GUC_UNIT_MS|GUC_UNIT_S|GUC_UNIT_MIN)
141+
#define GUC_UNIT_TIME 0x7000 /* mask for MS, S, MIN */
141142

142143
/* bit values in status field */
143144
#define GUC_HAVE_TENTATIVE 0x0001 /* tentative value is defined */

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