From 6430e6e2831dc35a6e45bf09baac8c0c212d71d7 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 19 Oct 2001 17:03:08 +0000 Subject: [PATCH] Ensure that all startup paths (postmaster, standalone postgres, or bootstrap) check for a valid PG_VERSION file before looking at anything else in the data directory. This fixes confusing error report when trying to start current sources in a pre-7.1 data directory. Per trouble report from Rich Shepard 10/18/01. --- src/backend/bootstrap/bootstrap.c | 6 ++++-- src/backend/postmaster/postmaster.c | 12 ++++++------ src/backend/tcop/postgres.c | 10 ++++++++-- src/backend/utils/init/miscinit.c | 8 +++----- src/backend/utils/init/postinit.c | 10 ++-------- src/bin/initdb/initdb.sh | 10 ++++++---- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 76d4d0252d..817ed4c8c8 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.117 2001/09/29 04:02:22 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.118 2001/10/19 17:03:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -303,11 +303,13 @@ BootstrapMain(int argc, char *argv[]) } SetDataDir(potential_DataDir); } + + /* Validate we have been given a reasonable-looking DataDir */ Assert(DataDir); + ValidatePgVersion(DataDir); if (IsUnderPostmaster) { - /* * Properly accept or ignore signals the postmaster might send us */ diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 8c5eb5ae90..024f62de01 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.246 2001/10/19 00:44:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.247 2001/10/19 17:03:08 tgl Exp $ * * NOTES * @@ -287,6 +287,9 @@ checkDataDir(const char *checkdir) ExitPostmaster(2); } + /* Look for PG_VERSION before looking for pg_control */ + ValidatePgVersion(checkdir); + snprintf(path, sizeof(path), "%s/global/pg_control", checkdir); fp = AllocateFile(path, PG_BINARY_R); @@ -299,10 +302,7 @@ checkDataDir(const char *checkdir) progname, checkdir, path, strerror(errno)); ExitPostmaster(2); } - FreeFile(fp); - - ValidatePgVersion(checkdir); } @@ -2438,10 +2438,10 @@ SSDataBase(int xlop) av[ac++] = "-d"; - sprintf(nbbuf, "-B%u", NBuffers); + sprintf(nbbuf, "-B%d", NBuffers); av[ac++] = nbbuf; - sprintf(xlbuf, "-x %d", xlop); + sprintf(xlbuf, "-x%d", xlop); av[ac++] = xlbuf; av[ac++] = "-p"; diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index bd51a57ab5..95d4b9e8c1 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.235 2001/10/19 00:44:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.236 2001/10/19 17:03:08 tgl Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -1584,6 +1584,12 @@ PostgresMain(int argc, char *argv[], } /* + * Validate we have been given a reasonable-looking DataDir + * (if under postmaster, assume postmaster did this already). + */ + ValidatePgVersion(DataDir); + + /* * Create lockfile for data directory. */ if (!CreateDataDirLockFile(DataDir, false)) @@ -1645,7 +1651,7 @@ PostgresMain(int argc, char *argv[], if (!IsUnderPostmaster) { puts("\nPOSTGRES backend interactive interface "); - puts("$Revision: 1.235 $ $Date: 2001/10/19 00:44:08 $\n"); + puts("$Revision: 1.236 $ $Date: 2001/10/19 17:03:08 $\n"); } /* diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 6f6bc5f9fd..2513d74f76 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.78 2001/10/12 02:08:34 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.79 2001/10/19 17:03:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -912,10 +912,8 @@ ValidatePgVersion(const char *path) } ret = fscanf(file, "%ld.%ld", &file_major, &file_minor); - if (ret == EOF) - elog(FATAL, "cannot read %s: %m", full_path); - else if (ret != 2) - elog(FATAL, "`%s' does not have a valid format. You need to initdb.", full_path); + if (ret != 2) + elog(FATAL, "File %s does not contain valid data. You need to initdb.", full_path); FreeFile(file); diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 47926b146f..f653f55640 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.93 2001/09/29 04:02:25 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.94 2001/10/19 17:03:08 tgl Exp $ * * *------------------------------------------------------------------------- @@ -221,13 +221,7 @@ InitPostgres(const char *dbname, const char *username) char *fullpath, datpath[MAXPGPATH]; - /* Verify if DataDir is ok */ - if (access(DataDir, F_OK) == -1) - elog(FATAL, "Database system not found.\n\t" - "Data directory '%s' does not exist.", - DataDir); - - ValidatePgVersion(DataDir); + /* Formerly we validated DataDir here, but now that's done earlier. */ /* * Find oid and path of the database we're about to open. Since diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 6ec85b30a4..0c73e46215 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -27,7 +27,7 @@ # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.139 2001/10/16 20:51:35 tgl Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.140 2001/10/19 17:03:08 tgl Exp $ # #------------------------------------------------------------------------- @@ -463,13 +463,17 @@ $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 +echo "$short_version" > "$PGDATA/PG_VERSION" || exit_nicely + cat "$POSTGRES_BKI" \ | sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \ -e "s/ENCODING/$MULTIBYTEID/g" \ | "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BACKEND_TALK_ARG template1 \ || exit_nicely -echo $short_version > "$PGDATA"/base/1/PG_VERSION || 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" @@ -479,8 +483,6 @@ echo "ok" $ECHO_N "creating configuration files... "$ECHO_C -echo $short_version > "$PGDATA/PG_VERSION" || exit_nicely - cp "$PG_HBA_SAMPLE" "$PGDATA"/pg_hba.conf || exit_nicely cp "$PG_IDENT_SAMPLE" "$PGDATA"/pg_ident.conf || exit_nicely cp "$POSTGRESQL_CONF_SAMPLE" "$PGDATA"/postgresql.conf || exit_nicely -- 2.11.0