Blame SOURCES/postgresql-check-db-dir

7686b4
#!/bin/sh
7686b4
7686b4
# This script verifies that the postgresql data directory has been correctly
7686b4
# initialized.  We do not want to automatically initdb it, because that has
7686b4
# a risk of catastrophic failure (ie, overwriting a valuable database) in
7686b4
# corner cases, such as a remotely mounted database on a volume that's a
7686b4
# bit slow to mount.  But we can at least emit a message advising newbies
7686b4
# what to do.
7686b4
7686b4
PGDATA="$1"
7686b4
7686b4
if [ -z "$PGDATA" ]
7686b4
then
7686b4
    echo "Usage: $0 database-path"
7686b4
    exit 1
7686b4
fi
7686b4
7686b4
# PGVERSION is the full package version, e.g., 9.1.2
7686b4
# Note: the specfile inserts the correct value during package build
7686b4
PGVERSION=xxxx
7686b4
# PGMAJORVERSION is major version, e.g., 9.1 (this should match PG_VERSION)
7686b4
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`
7686b4
# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades
7686b4
# Note: the specfile inserts the correct value during package build
7686b4
PREVMAJORVERSION=xxxx
7686b4
# PGDOCDIR is the directory containing the package's documentation
7686b4
# Note: the specfile inserts the correct value during package build
7686b4
PGDOCDIR=xxxx
7686b4
7686b4
# Check for the PGDATA structure
7686b4
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
7686b4
then
7686b4
    # Check version of existing PGDATA
7686b4
    if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
7686b4
    then
7686b4
        : A-OK
7686b4
    elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
7686b4
    then
7686b4
        echo $"An old version of the database format was found."
7686b4
        echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION."
7686b4
        echo $"See $PGDOCDIR/README.rpm-dist for more information."
7686b4
        exit 1
7686b4
    else
7686b4
        echo $"An old version of the database format was found."
7686b4
        echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
7686b4
        echo $"See $PGDOCDIR/README.rpm-dist for more information."
7686b4
        exit 1
7686b4
    fi
7686b4
else
7686b4
    # No existing PGDATA! Warn the user to initdb it.
7686b4
    echo $"\"$PGDATA\" is missing or empty."
7686b4
    echo $"Use \"postgresql-setup initdb\" to initialize the database cluster."
7686b4
    echo $"See $PGDOCDIR/README.rpm-dist for more information."
7686b4
    exit 1
7686b4
fi
7686b4
7686b4
exit 0