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);
169169static void check_input (char * path );
170170static void set_short_version (char * short_version ,char * extrapath );
171171static void set_null_conf (void );
172- static void test_connections (void );
173- static void test_buffers (void );
172+ static void test_config_settings (void );
174173static void setup_config (void );
175174static void bootstrap_template1 (char * short_version );
176175static void setup_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 */
10641064static void
10651065set_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- #define TEST_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 */
10971094static void
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+ #define MIN_BUFS_FOR_CONNS (nconns ) ((nconns) * 10)
1107+ #define FSM_FOR_BUFS (nbuffers ) ((nbuffers) > 1000 ? 50 * (nbuffers) : 20000)
1108+
1109+ static const int trial_conns []= {
1110+ 100 ,50 ,40 ,30 ,20 ,10
1111+ };
1112+ static const int trial_bufs []= {
1113+ 4000 ,3500 ,3000 ,2500 ,2000 ,1500 ,
1114+ 1000 ,900 ,800 ,700 ,600 ,500 ,
1115+ 400 ,300 ,200 ,100 ,50
1116+ };
1117+
11001118char cmd [MAXPGPATH ];
1101- static const int conns [] = { 100 , 50 , 40 , 30 , 20 , 10 } ;
1102- static const int len = sizeof (conns ) /sizeof (int );
1119+ const int connslen = sizeof ( trial_conns ) / sizeof ( int ) ;
1120+ const int bufslen = sizeof (trial_bufs ) /sizeof (int );
11031121int i ,
1104- status ;
1122+ status ,
1123+ test_conns ,
1124+ test_buffs ,
1125+ test_max_fsm ;
11051126
11061127printf (_ ("selecting default max_connections ... " ));
11071128fflush (stdout );
11081129
1109- for (i = 0 ;i < len ;i ++ )
1130+ for (i = 0 ;i < connslen ;i ++ )
11101131{
1111- int test_buffs = conns [i ]* 5 ;
1112- int test_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
11141136snprintf (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" ,
11191142SYSTEMQUOTE ,backend_exec ,boot_options ,
1120- test_max_fsm ,
1121- test_buffs ,conns [i ],
1143+ test_conns ,test_buffs ,test_max_fsm ,
11221144DEVNULL ,DEVNULL ,SYSTEMQUOTE );
11231145status = system (cmd );
11241146if (status == 0 )
11251147break ;
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
11311153printf ("%d\n" ,n_connections );
1132- }
1133-
1134- /*
1135- * check how many buffers we can run with
1136- */
1137- static void
1138- test_buffers (void )
1139- {
1140- char cmd [MAXPGPATH ];
1141- static const int bufs []= {
1142- 4000 ,3500 ,3000 ,2500 ,2000 ,1500 ,
1143- 1000 ,900 ,800 ,700 ,600 ,500 ,
1144- 400 ,300 ,200 ,100 ,50
1145- };
1146- static const int len = sizeof (bufs ) /sizeof (int );
1147- int i ,
1148- status ,
1149- test_max_fsm_pages ;
11501154
11511155printf (_ ("selecting default shared_buffers/max_fsm_pages ... " ));
11521156fflush (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
11581163snprintf (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" ,
11631169SYSTEMQUOTE ,backend_exec ,boot_options ,
1164- test_max_fsm_pages ,
1165- bufs [i ],n_connections ,
1170+ n_connections ,test_buffs ,test_max_fsm ,
11661171DEVNULL ,DEVNULL ,SYSTEMQUOTE );
11671172status = system (cmd );
11681173if (status == 0 )
11691174break ;
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
11761181printf ("%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 */
27462751set_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 */
27562754set_null_conf ();
2757-
2758- test_connections ();
2759- test_buffers ();
2755+ test_config_settings ();
27602756
27612757/* Now create all the text config files */
27622758setup_config ();