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.
This commit is contained in:
Tom Lane 2001-10-19 17:03:08 +00:00
parent 3d510653a4
commit 6430e6e283
6 changed files with 29 additions and 27 deletions

View file

@ -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
*/

View file

@ -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";

View file

@ -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
@ -1583,6 +1583,12 @@ PostgresMain(int argc, char *argv[],
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.
*/
@ -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");
}
/*

View file

@ -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);

View file

@ -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

View file

@ -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