summaryrefslogtreecommitdiffstats
path: root/postgresql-check-db-dir.in
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2014-07-01 13:41:43 +0200
committerPavel Raiskup <praiskup@redhat.com>2014-07-01 13:44:30 +0200
commit7b1bb4fd5a05b9c35ae23734f12b2a92fe5f0a57 (patch)
treebe4ca41ca8c8c169440fd5e4b474ff420867a791 /postgresql-check-db-dir.in
parent6472bbf1c6d2ad140a7502a7788ed6c4a9193a7d (diff)
downloadpostgresql-setup-7b1bb4fd5a05b9c35ae23734f12b2a92fe5f0a57.tar.gz
postgresql-setup-7b1bb4fd5a05b9c35ae23734f12b2a92fe5f0a57.tar.xz
postgresql-setup-7b1bb4fd5a05b9c35ae23734f12b2a92fe5f0a57.zip
postgresql-check-db-dir generated also
Also generate files using sed as is suggested by autoconf manual (and the autoconf project does so internally).
Diffstat (limited to 'postgresql-check-db-dir.in')
-rw-r--r--postgresql-check-db-dir.in57
1 files changed, 57 insertions, 0 deletions
diff --git a/postgresql-check-db-dir.in b/postgresql-check-db-dir.in
new file mode 100644
index 0000000..3514247
--- /dev/null
+++ b/postgresql-check-db-dir.in
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# This script verifies that the postgresql data directory has been correctly
+# initialized. We do not want to automatically initdb it, because that has
+# a risk of catastrophic failure (ie, overwriting a valuable database) in
+# corner cases, such as a remotely mounted database on a volume that's a
+# bit slow to mount. But we can at least emit a message advising newbies
+# what to do.
+
+PGDATA="$1"
+
+if [ -z "$PGDATA" ]
+then
+ echo "Usage: $0 database-path"
+ exit 1
+fi
+
+# Full PostgreSQL version, e.g. 9.0.2
+PGVERSION=@PGVERSION@
+
+# Major version of PostgreSQL, e.g. 9.0
+PGMAJORVERSION=@PGMAJORVERSION@
+
+# Previous major version, e.g., 8.4, for upgrades
+PREVMAJORVERSION=@PREVMAJORVERSION@
+
+# Directory containing the postgresql package's documentation
+PGDOCDIR=@pgdocdir@
+
+# Check for the PGDATA structure
+if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
+then
+ # Check version of existing PGDATA
+ if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
+ then
+ : A-OK
+ elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
+ then
+ echo $"An old version of the database format was found."
+ echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+ else
+ echo $"An old version of the database format was found."
+ echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+ fi
+else
+ # No existing PGDATA! Warn the user to initdb it.
+ echo $"\"$PGDATA\" is missing or empty."
+ echo $"Use \"postgresql-setup initdb\" to initialize the database cluster."
+ echo $"See $PGDOCDIR/README.rpm-dist for more information."
+ exit 1
+fi
+
+exit 0