Created
October 26, 2017 10:00
-
-
Save tdegrunt/44ed3cae8775f6c278ae32b1b55935fd to your computer and use it in GitHub Desktop.
Auto-upgrade homebrew's PostgreSQL data directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
old=$1 | |
new=$2 | |
if ! [ "$new" ]; then | |
new=`psql -V | cut -d' ' -f3` | |
fi | |
if ! [ "$old" ]; then | |
echo "Usage: pgupgrade.sh <old-version> [new-version]" | |
echo | |
echo "Please specify complete old version (i.e. 9.6.5)" | |
echo "Assumption is that the new psql ($new) is already active in path, if not please indicate it in arguments" | |
exit | |
fi | |
echo Upgrading PostgreSQL data directory from $old to $new | |
echo "=== Stopping postgresql ===============================" | |
brew services stop postgresql | |
echo "=== Making new data directory =========================" | |
initdb /usr/local/var/postgres$new -E utf8 | |
echo "=== Upgrading data ====================================" | |
pg_upgrade -d /usr/local/var/postgres -D /usr/local/var/postgres$new -b /usr/local/Cellar/postgresql/$old/bin -B /usr/local/Cellar/postgresql/$new/bin -v | |
echo "=== Moving old data aside =============================" | |
mv /usr/local/var/postgres /usr/local/var/postgres$old | |
echo "=== Moving new data in place ==========================" | |
mv /usr/local/var/postgres$new /usr/local/var/postgres | |
echo "=== Start postgresql ==================================" | |
brew services start postgresql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./pgupgrade.sh 9.6.5
Let me know if there are issues.