3 # This script verifies that the postgresql data directory has been correctly
4 # initialized. We do not want to automatically initdb it, because that has
5 # a risk of catastrophic failure (ie, overwriting a valuable database) in
6 # corner cases, such as a remotely mounted database on a volume that's a
7 # bit slow to mount. But we can at least emit a message advising newbies
14 echo "Usage: $0 database-path"
18 # PGMAJORVERSION is major version
20 # PREVMAJORVERSION is the previous major version
23 # Check for the PGDATA structure
24 if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
26 # Check version of existing PGDATA
27 if [ x
`cat "$PGDATA/PG_VERSION"` = x
"$PGMAJORVERSION" ]
30 elif [ x
`cat "$PGDATA/PG_VERSION"` = x
"$PREVMAJORVERSION" ]
32 echo $
"An old version of the database format was found."
33 echo $
"See https://wiki.archlinux.org/index.php/PostgreSQL#Upgrading_PostgreSQL"
36 echo $
"An old version of the database format was found."
37 echo $
"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
38 echo $
"See http://www.postgresql.org/docs/$PGMAJORVERSION/static/upgrading.html"
42 # No existing PGDATA! Warn the user to initdb it.
43 echo $
"\"$PGDATA\" is missing or empty. Use a command like"
44 echo $
" su - postgres -c \"initdb --locale en_US.UTF-8 -D '$PGDATA'\""
45 echo $
"with relevant options, to initialize the database cluster."