summaryrefslogtreecommitdiffstats
path: root/abs/extra/postgresql/postgresql-check-db-dir
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2018-03-02 23:35:59 (GMT)
committerBritney Fransen <brfransen@gmail.com>2018-03-02 23:35:59 (GMT)
commitfd8405efa6e0c17c9e666f5ea8584039f31a5168 (patch)
tree641cafbb31cb0387ac10b0641427d850d15a4b93 /abs/extra/postgresql/postgresql-check-db-dir
parent1577770bf29c22dd1a2e14c055b5af2f1408eb39 (diff)
downloadlinhes_pkgbuild-fd8405efa6e0c17c9e666f5ea8584039f31a5168.zip
linhes_pkgbuild-fd8405efa6e0c17c9e666f5ea8584039f31a5168.tar.gz
linhes_pkgbuild-fd8405efa6e0c17c9e666f5ea8584039f31a5168.tar.bz2
postgresql: update to 10.2
Diffstat (limited to 'abs/extra/postgresql/postgresql-check-db-dir')
-rwxr-xr-xabs/extra/postgresql/postgresql-check-db-dir49
1 files changed, 49 insertions, 0 deletions
diff --git a/abs/extra/postgresql/postgresql-check-db-dir b/abs/extra/postgresql/postgresql-check-db-dir
new file mode 100755
index 0000000..acf73eb
--- /dev/null
+++ b/abs/extra/postgresql/postgresql-check-db-dir
@@ -0,0 +1,49 @@
+#!/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
+
+# PGMAJORVERSION is major version
+PGMAJORVERSION=10
+# PREVMAJORVERSION is the previous major version
+PREVMAJORVERSION=9.6
+
+# 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 $"See https://wiki.archlinux.org/index.php/PostgreSQL#Upgrading_PostgreSQL"
+ 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 http://www.postgresql.org/docs/$PGMAJORVERSION/static/upgrading.html"
+ exit 1
+ fi
+else
+ # No existing PGDATA! Warn the user to initdb it.
+ echo $"\"$PGDATA\" is missing or empty. Use a command like"
+ echo $" su - postgres -c \"initdb --locale en_US.UTF-8 -D '$PGDATA'\""
+ echo $"with relevant options, to initialize the database cluster."
+ exit 1
+fi
+
+exit 0