Commit 6430e6e2 authored by Tom Lane's avatar Tom Lane

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.
parent 3d510653
...@@ -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.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[]) ...@@ -303,11 +303,13 @@ BootstrapMain(int argc, char *argv[])
} }
SetDataDir(potential_DataDir); SetDataDir(potential_DataDir);
} }
/* Validate we have been given a reasonable-looking DataDir */
Assert(DataDir); Assert(DataDir);
ValidatePgVersion(DataDir);
if (IsUnderPostmaster) if (IsUnderPostmaster)
{ {
/* /*
* Properly accept or ignore signals the postmaster might send us * Properly accept or ignore signals the postmaster might send us
*/ */
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
...@@ -287,6 +287,9 @@ checkDataDir(const char *checkdir) ...@@ -287,6 +287,9 @@ checkDataDir(const char *checkdir)
ExitPostmaster(2); ExitPostmaster(2);
} }
/* Look for PG_VERSION before looking for pg_control */
ValidatePgVersion(checkdir);
snprintf(path, sizeof(path), "%s/global/pg_control", checkdir); snprintf(path, sizeof(path), "%s/global/pg_control", checkdir);
fp = AllocateFile(path, PG_BINARY_R); fp = AllocateFile(path, PG_BINARY_R);
...@@ -299,10 +302,7 @@ checkDataDir(const char *checkdir) ...@@ -299,10 +302,7 @@ checkDataDir(const char *checkdir)
progname, checkdir, path, strerror(errno)); progname, checkdir, path, strerror(errno));
ExitPostmaster(2); ExitPostmaster(2);
} }
FreeFile(fp); FreeFile(fp);
ValidatePgVersion(checkdir);
} }
...@@ -2438,10 +2438,10 @@ SSDataBase(int xlop) ...@@ -2438,10 +2438,10 @@ SSDataBase(int xlop)
av[ac++] = "-d"; av[ac++] = "-d";
sprintf(nbbuf, "-B%u", NBuffers); sprintf(nbbuf, "-B%d", NBuffers);
av[ac++] = nbbuf; av[ac++] = nbbuf;
sprintf(xlbuf, "-x %d", xlop); sprintf(xlbuf, "-x%d", xlop);
av[ac++] = xlbuf; av[ac++] = xlbuf;
av[ac++] = "-p"; av[ac++] = "-p";
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -1583,6 +1583,12 @@ PostgresMain(int argc, char *argv[], ...@@ -1583,6 +1583,12 @@ PostgresMain(int argc, char *argv[],
proc_exit(1); proc_exit(1);
} }
/*
* Validate we have been given a reasonable-looking DataDir
* (if under postmaster, assume postmaster did this already).
*/
ValidatePgVersion(DataDir);
/* /*
* Create lockfile for data directory. * Create lockfile for data directory.
*/ */
...@@ -1645,7 +1651,7 @@ PostgresMain(int argc, char *argv[], ...@@ -1645,7 +1651,7 @@ PostgresMain(int argc, char *argv[],
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); 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");
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -912,10 +912,8 @@ ValidatePgVersion(const char *path)
} }
ret = fscanf(file, "%ld.%ld", &file_major, &file_minor); ret = fscanf(file, "%ld.%ld", &file_major, &file_minor);
if (ret == EOF) if (ret != 2)
elog(FATAL, "cannot read %s: %m", full_path); elog(FATAL, "File %s does not contain valid data. You need to initdb.", full_path);
else if (ret != 2)
elog(FATAL, "`%s' does not have a valid format. You need to initdb.", full_path);
FreeFile(file); FreeFile(file);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -221,13 +221,7 @@ InitPostgres(const char *dbname, const char *username)
char *fullpath, char *fullpath,
datpath[MAXPGPATH]; datpath[MAXPGPATH];
/* Verify if DataDir is ok */ /* Formerly we validated DataDir here, but now that's done earlier. */
if (access(DataDir, F_OK) == -1)
elog(FATAL, "Database system not found.\n\t"
"Data directory '%s' does not exist.",
DataDir);
ValidatePgVersion(DataDir);
/* /*
* Find oid and path of the database we're about to open. Since * Find oid and path of the database we're about to open. Since
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2001, 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.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 ...@@ -463,13 +463,17 @@ $ECHO_N "creating template1 database in $PGDATA/base/1... "$ECHO_C
rm -rf "$PGDATA"/base/1 || exit_nicely rm -rf "$PGDATA"/base/1 || exit_nicely
mkdir "$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" \ cat "$POSTGRES_BKI" \
| sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \ | sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
-e "s/ENCODING/$MULTIBYTEID/g" \ -e "s/ENCODING/$MULTIBYTEID/g" \
| "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BACKEND_TALK_ARG template1 \ | "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BACKEND_TALK_ARG template1 \
|| exit_nicely || 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" echo "ok"
...@@ -479,8 +483,6 @@ echo "ok" ...@@ -479,8 +483,6 @@ echo "ok"
$ECHO_N "creating configuration files... "$ECHO_C $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_HBA_SAMPLE" "$PGDATA"/pg_hba.conf || exit_nicely
cp "$PG_IDENT_SAMPLE" "$PGDATA"/pg_ident.conf || exit_nicely cp "$PG_IDENT_SAMPLE" "$PGDATA"/pg_ident.conf || exit_nicely
cp "$POSTGRESQL_CONF_SAMPLE" "$PGDATA"/postgresql.conf || exit_nicely cp "$POSTGRESQL_CONF_SAMPLE" "$PGDATA"/postgresql.conf || exit_nicely
......
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