Commit 9117e554 authored by Tom Lane's avatar Tom Lane

Tweak original coding so that we can determine the platform-specific

shared_buffers and max_connections values to use before we run the
bootstrap process.  Without this, initdb would fail on platforms where
the hardwired default values are too large.  (We could get around that
by making the hardwired defaults tiny, perhaps, but why slow down
bootstrap by starving it for buffers...)
parent 683f4d0a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.160 2003/05/28 18:19:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.161 2003/07/15 00:11:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -187,15 +187,16 @@ err_out(void) ...@@ -187,15 +187,16 @@ err_out(void)
} }
/* usage: /* usage:
usage help for the bootstrap backen * usage help for the bootstrap backend
*/ */
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, fprintf(stderr,
gettext("Usage:\n" gettext("Usage:\n"
" postgres -boot [-d level] [-D datadir] [-F] [-o file] [-x num] dbname\n" " postgres -boot [OPTION]... DBNAME\n"
" -d 1-5 debug mode\n" " -c NAME=VALUE set run-time parameter\n"
" -d 1-5 debug level\n"
" -D datadir data directory\n" " -D datadir data directory\n"
" -F turn off fsync\n" " -F turn off fsync\n"
" -o file send debug output to file\n" " -o file send debug output to file\n"
...@@ -253,7 +254,7 @@ BootstrapMain(int argc, char *argv[]) ...@@ -253,7 +254,7 @@ BootstrapMain(int argc, char *argv[])
* variable */ * variable */
} }
while ((flag = getopt(argc, argv, "B:d:D:Fo:p:x:")) != -1) while ((flag = getopt(argc, argv, "B:c:d:D:Fo:p:x:-:")) != -1)
{ {
switch (flag) switch (flag)
{ {
...@@ -303,6 +304,27 @@ BootstrapMain(int argc, char *argv[]) ...@@ -303,6 +304,27 @@ BootstrapMain(int argc, char *argv[])
case 'B': case 'B':
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV); SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break; break;
case 'c':
case '-':
{
char *name,
*value;
ParseLongOption(optarg, &name, &value);
if (!value)
{
if (flag == '-')
elog(ERROR, "--%s requires argument", optarg);
else
elog(ERROR, "-c %s requires argument", optarg);
}
SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
free(name);
if (value)
free(value);
break;
}
default: default:
usage(); usage();
break; break;
...@@ -408,7 +430,6 @@ BootstrapMain(int argc, char *argv[]) ...@@ -408,7 +430,6 @@ BootstrapMain(int argc, char *argv[])
switch (xlogop) switch (xlogop)
{ {
case BS_XLOG_NOP: case BS_XLOG_NOP:
StartupXLOG();
break; break;
case BS_XLOG_BOOTSTRAP: case BS_XLOG_BOOTSTRAP:
...@@ -445,6 +466,15 @@ BootstrapMain(int argc, char *argv[]) ...@@ -445,6 +466,15 @@ BootstrapMain(int argc, char *argv[])
*/ */
InitPostgres(dbname, NULL); InitPostgres(dbname, NULL);
/*
* In NOP mode, all we really want to do is create shared memory and
* semaphores (just to prove we can do it with the current GUC settings).
* So, quit now.
*/
if (xlogop == BS_XLOG_NOP)
proc_exit(0);
/* Initialize stuff for bootstrap-file processing */
for (i = 0; i < MAXATTR; i++) for (i = 0; i < MAXATTR; i++)
{ {
attrtypes[i] = (Form_pg_attribute) NULL; attrtypes[i] = (Form_pg_attribute) NULL;
...@@ -456,7 +486,7 @@ BootstrapMain(int argc, char *argv[]) ...@@ -456,7 +486,7 @@ BootstrapMain(int argc, char *argv[])
hashtable[i] = NULL; hashtable[i] = NULL;
/* /*
* abort processing resumes here * abort processing resumes here (this is probably dead code?)
*/ */
if (sigsetjmp(Warn_restart, 1) != 0) if (sigsetjmp(Warn_restart, 1) != 0)
{ {
...@@ -465,20 +495,19 @@ BootstrapMain(int argc, char *argv[]) ...@@ -465,20 +495,19 @@ BootstrapMain(int argc, char *argv[])
} }
/* /*
* process input. * Process bootstrap input.
*/ *
/*
* the sed script boot.sed renamed yyparse to Int_yyparse for the * the sed script boot.sed renamed yyparse to Int_yyparse for the
* bootstrap parser to avoid conflicts with the normal SQL parser * bootstrap parser to avoid conflicts with the normal SQL parser
*/ */
Int_yyparse(); Int_yyparse();
/* Perform a checkpoint to ensure everything's down to disk */
SetProcessingMode(NormalProcessing); SetProcessingMode(NormalProcessing);
CreateCheckPoint(true, true); CreateCheckPoint(true, true);
SetProcessingMode(BootstrapProcessing); SetProcessingMode(BootstrapProcessing);
/* clean up processing */ /* Clean up and exit */
StartTransactionCommand(); StartTransactionCommand();
cleanup(); cleanup();
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.194 2003/07/14 20:00:23 tgl Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.195 2003/07/15 00:11:14 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -536,46 +536,9 @@ else ...@@ -536,46 +536,9 @@ else
fi fi
fi fi
##########################################################################
#
# RUN BKI SCRIPT IN BOOTSTRAP MODE TO CREATE TEMPLATE1
# common backend options
PGSQL_OPT="-F -D$PGDATA"
if [ "$debug" = yes ]
then
BOOTSTRAP_TALK_ARG="-d 5"
fi
$ECHO_N "creating template1 database in $PGDATA/base/1... "$ECHO_C
rm -rf "$PGDATA"/base/1 || exit_nicely
mkdir "$PGDATA"/base/1 || exit_nicely
# Top level PG_VERSION is checked by bootstrapper, so make it first # Top level PG_VERSION is checked by bootstrapper, so make it first
echo "$short_version" > "$PGDATA/PG_VERSION" || exit_nicely echo "$short_version" > "$PGDATA/PG_VERSION" || exit_nicely
cat "$POSTGRES_BKI" \
| sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
-e "s/ENCODING/$ENCODINGID/g" \
|
(
LC_COLLATE=`pg_getlocale COLLATE`
LC_CTYPE=`pg_getlocale CTYPE`
export LC_COLLATE
export LC_CTYPE
unset LC_ALL
"$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BOOTSTRAP_TALK_ARG template1
) \
|| exit_nicely
# Make the per-database PGVERSION for template1 only after init'ing it
echo "$short_version" > "$PGDATA/base/1/PG_VERSION" || exit_nicely
echo "ok"
########################################################################## ##########################################################################
# #
...@@ -583,6 +546,9 @@ echo "ok" ...@@ -583,6 +546,9 @@ echo "ok"
# #
# Use reasonable values if kernel will let us, else scale back # Use reasonable values if kernel will let us, else scale back
# common backend options
PGSQL_OPT="-F -D$PGDATA"
cp /dev/null "$PGDATA"/postgresql.conf || exit_nicely cp /dev/null "$PGDATA"/postgresql.conf || exit_nicely
$ECHO_N "selecting default shared_buffers... "$ECHO_C $ECHO_N "selecting default shared_buffers... "$ECHO_C
...@@ -590,7 +556,7 @@ $ECHO_N "selecting default shared_buffers... "$ECHO_C ...@@ -590,7 +556,7 @@ $ECHO_N "selecting default shared_buffers... "$ECHO_C
for nbuffers in 1000 900 800 700 600 500 400 300 200 100 50 for nbuffers in 1000 900 800 700 600 500 400 300 200 100 50
do do
TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=5" TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=5"
if "$PGPATH"/postgres $TEST_OPT template1 </dev/null >/dev/null 2>&1 if "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1
then then
break break
fi fi
...@@ -603,7 +569,7 @@ $ECHO_N "selecting default max_connections... "$ECHO_C ...@@ -603,7 +569,7 @@ $ECHO_N "selecting default max_connections... "$ECHO_C
for nconns in 100 50 40 30 20 10 for nconns in 100 50 40 30 20 10
do do
TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=$nconns" TEST_OPT="$PGSQL_OPT -c shared_buffers=$nbuffers -c max_connections=$nconns"
if "$PGPATH"/postgres $TEST_OPT template1 </dev/null >/dev/null 2>&1 if "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1
then then
break break
fi fi
...@@ -632,6 +598,39 @@ chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/pg_ident.conf \ ...@@ -632,6 +598,39 @@ chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/pg_ident.conf \
echo "ok" echo "ok"
##########################################################################
#
# RUN BKI SCRIPT IN BOOTSTRAP MODE TO CREATE TEMPLATE1
if [ "$debug" = yes ]
then
BOOTSTRAP_TALK_ARG="-d 5"
fi
$ECHO_N "creating template1 database in $PGDATA/base/1... "$ECHO_C
rm -rf "$PGDATA"/base/1 || exit_nicely
mkdir "$PGDATA"/base/1 || exit_nicely
cat "$POSTGRES_BKI" \
| sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
-e "s/ENCODING/$ENCODINGID/g" \
|
(
LC_COLLATE=`pg_getlocale COLLATE`
LC_CTYPE=`pg_getlocale CTYPE`
export LC_COLLATE
export LC_CTYPE
unset LC_ALL
"$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BOOTSTRAP_TALK_ARG template1
) \
|| exit_nicely
# Make the per-database PGVERSION for template1 only after init'ing it
echo "$short_version" > "$PGDATA/base/1/PG_VERSION" || exit_nicely
echo "ok"
########################################################################## ##########################################################################
# #
# CREATE VIEWS and other things # CREATE VIEWS and other things
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment