Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcb26d7

Browse files
committed
Clean up initdb's code for selecting max_connections and shared_buffers
a little bit, and set the minimum buffers-per-connection ratio to 10 not5. I folded the two test routines into one to counteract the illusionthat the tests can be twiddled independently, and added some documentationpointing out the necessary connection between the sets of values tested.Fixes strange choices of parameters that I noticed CVS tip making onDarwin with Apple's undersized default SHMMAX.
1 parentdbf53e6 commitbcb26d7

File tree

1 file changed

+61
-65
lines changed

1 file changed

+61
-65
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 61 additions & 65 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.102 2005/12/27 23:54:01 adunstan Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.103 2005/12/31 23:50:59 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -169,8 +169,7 @@ static void set_input(char **dest, char *filename);
169169
staticvoidcheck_input(char*path);
170170
staticvoidset_short_version(char*short_version,char*extrapath);
171171
staticvoidset_null_conf(void);
172-
staticvoidtest_connections(void);
173-
staticvoidtest_buffers(void);
172+
staticvoidtest_config_settings(void);
174173
staticvoidsetup_config(void);
175174
staticvoidbootstrap_template1(char*short_version);
176175
staticvoidsetup_auth(void);
@@ -1059,7 +1058,8 @@ set_short_version(char *short_version, char *extrapath)
10591058
}
10601059

10611060
/*
1062-
* set up an empty config file so we can check buffers and connections
1061+
* set up an empty config file so we can check config settings by launching
1062+
* a test backend
10631063
*/
10641064
staticvoid
10651065
set_null_conf(void)
@@ -1085,93 +1085,98 @@ set_null_conf(void)
10851085
}
10861086

10871087
/*
1088-
* max_fsm_pages setting used in both the shared_buffers and max_connections
1089-
* tests.
1090-
*/
1091-
1092-
#defineTEST_FSM(x) ( (x) > 1000 ? 50 * (x) : 20000 )
1093-
1094-
/*
1095-
* check how many connections we can sustain
1088+
* Determine platform-specific config settings
1089+
*
1090+
* Use reasonable values if kernel will let us, else scale back. Probe
1091+
* for max_connections first since it is subject to more constraints than
1092+
* shared_buffers.
10961093
*/
10971094
staticvoid
1098-
test_connections(void)
1095+
test_config_settings(void)
10991096
{
1097+
/*
1098+
* These macros define the minimum shared_buffers we want for a given
1099+
* max_connections value, and the max_fsm_pages setting to be used for
1100+
* a given shared_buffers value. The arrays show the settings to try.
1101+
*
1102+
* Make sure the trial_bufs[] list includes the MIN_BUFS_FOR_CONNS()
1103+
* value for each trial_conns[] entry, else we may end up setting
1104+
* shared_buffers lower than it could be.
1105+
*/
1106+
#defineMIN_BUFS_FOR_CONNS(nconns) ((nconns) * 10)
1107+
#defineFSM_FOR_BUFS(nbuffers) ((nbuffers) > 1000 ? 50 * (nbuffers) : 20000)
1108+
1109+
staticconstinttrial_conns[]= {
1110+
100,50,40,30,20,10
1111+
};
1112+
staticconstinttrial_bufs[]= {
1113+
4000,3500,3000,2500,2000,1500,
1114+
1000,900,800,700,600,500,
1115+
400,300,200,100,50
1116+
};
1117+
11001118
charcmd[MAXPGPATH];
1101-
staticconstintconns[]={100,50,40,30,20,10};
1102-
staticconstintlen=sizeof(conns) /sizeof(int);
1119+
constintconnslen=sizeof(trial_conns) /sizeof(int);
1120+
constintbufslen=sizeof(trial_bufs) /sizeof(int);
11031121
inti,
1104-
status;
1122+
status,
1123+
test_conns,
1124+
test_buffs,
1125+
test_max_fsm;
11051126

11061127
printf(_("selecting default max_connections ... "));
11071128
fflush(stdout);
11081129

1109-
for (i=0;i<len;i++)
1130+
for (i=0;i<connslen;i++)
11101131
{
1111-
inttest_buffs=conns[i]*5;
1112-
inttest_max_fsm=TEST_FSM(test_buffs);
1132+
test_conns=trial_conns[i];
1133+
test_buffs=MIN_BUFS_FOR_CONNS(test_conns);
1134+
test_max_fsm=FSM_FOR_BUFS(test_buffs);
11131135

11141136
snprintf(cmd,sizeof(cmd),
11151137
"%s\"%s\" -boot -x0 %s "
1138+
"-c max_connections=%d "
1139+
"-c shared_buffers=%d "
11161140
"-c max_fsm_pages=%d "
1117-
"-c shared_buffers=%d -c max_connections=%d template1 "
1118-
"< \"%s\" > \"%s\" 2>&1%s",
1141+
"template1 < \"%s\" > \"%s\" 2>&1%s",
11191142
SYSTEMQUOTE,backend_exec,boot_options,
1120-
test_max_fsm,
1121-
test_buffs,conns[i],
1143+
test_conns,test_buffs,test_max_fsm,
11221144
DEVNULL,DEVNULL,SYSTEMQUOTE);
11231145
status=system(cmd);
11241146
if (status==0)
11251147
break;
11261148
}
1127-
if (i >=len)
1128-
i=len-1;
1129-
n_connections=conns[i];
1149+
if (i >=connslen)
1150+
i=connslen-1;
1151+
n_connections=trial_conns[i];
11301152

11311153
printf("%d\n",n_connections);
1132-
}
1133-
1134-
/*
1135-
* check how many buffers we can run with
1136-
*/
1137-
staticvoid
1138-
test_buffers(void)
1139-
{
1140-
charcmd[MAXPGPATH];
1141-
staticconstintbufs[]= {
1142-
4000,3500,3000,2500,2000,1500,
1143-
1000,900,800,700,600,500,
1144-
400,300,200,100,50
1145-
};
1146-
staticconstintlen=sizeof(bufs) /sizeof(int);
1147-
inti,
1148-
status,
1149-
test_max_fsm_pages;
11501154

11511155
printf(_("selecting default shared_buffers/max_fsm_pages ... "));
11521156
fflush(stdout);
11531157

1154-
for (i=0;i<len;i++)
1158+
for (i=0;i<bufslen;i++)
11551159
{
1156-
test_max_fsm_pages=TEST_FSM(bufs[i]);
1160+
test_buffs=trial_bufs[i];
1161+
test_max_fsm=FSM_FOR_BUFS(test_buffs);
11571162

11581163
snprintf(cmd,sizeof(cmd),
11591164
"%s\"%s\" -boot -x0 %s "
1165+
"-c max_connections=%d "
1166+
"-c shared_buffers=%d "
11601167
"-c max_fsm_pages=%d "
1161-
"-c shared_buffers=%d -c max_connections=%d template1 "
1162-
"< \"%s\" > \"%s\" 2>&1%s",
1168+
"template1 < \"%s\" > \"%s\" 2>&1%s",
11631169
SYSTEMQUOTE,backend_exec,boot_options,
1164-
test_max_fsm_pages,
1165-
bufs[i],n_connections,
1170+
n_connections,test_buffs,test_max_fsm,
11661171
DEVNULL,DEVNULL,SYSTEMQUOTE);
11671172
status=system(cmd);
11681173
if (status==0)
11691174
break;
11701175
}
1171-
if (i >=len)
1172-
i=len-1;
1173-
n_buffers=bufs[i];
1174-
n_fsm_pages=test_max_fsm_pages;
1176+
if (i >=bufslen)
1177+
i=bufslen-1;
1178+
n_buffers=trial_bufs[i];
1179+
n_fsm_pages=FSM_FOR_BUFS(n_buffers);
11751180

11761181
printf("%d/%d\n",n_buffers,n_fsm_pages);
11771182
}
@@ -2745,18 +2750,9 @@ main(int argc, char *argv[])
27452750
/* Top level PG_VERSION is checked by bootstrapper, so make it first */
27462751
set_short_version(short_version,NULL);
27472752

2748-
/*
2749-
* Determine platform-specific config settings
2750-
*
2751-
* Use reasonable values if kernel will let us, else scale back. Probe
2752-
* for max_connections first since it is subject to more constraints than
2753-
* shared_buffers.
2754-
*/
2755-
2753+
/* Select suitable configuration settings */
27562754
set_null_conf();
2757-
2758-
test_connections();
2759-
test_buffers();
2755+
test_config_settings();
27602756

27612757
/* Now create all the text config files */
27622758
setup_config();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp