Skip to content

Instantly share code, notes, and snippets.

@JLHwung
Last active October 18, 2017 05:52
Show Gist options
  • Save JLHwung/4133804cf67dd87a36473396a3926563 to your computer and use it in GitHub Desktop.
Save JLHwung/4133804cf67dd87a36473396a3926563 to your computer and use it in GitHub Desktop.
homebrew-postgresql-upgrade-10
# install postgresql 10
brew upgrade postgresql
# Check version by `brew list --versions postgres`
export OLD_POSTGRES_VERSION=9.6.5;
export NEW_POSTGRES_VERSION=10.0;
# Stop postgresql service
brew services stop postgresql
initdb /usr/local/var/postgres$NEW_POSTGRES_VERSION -E utf8
pg_upgrade -v \
--old-datadir /usr/local/var/postgres \
--new-datadir /usr/local/var/postgres$NEW_POSTGRES_VERSION \
--old-bindir /usr/local/Cellar/postgresql/$OLD_POSTGRES_VERSION/bin \
--new-bindir /usr/local/Cellar/postgresql/$NEW_POSTGRES_VERSION/bin
# Rebase data
mv /usr/local/var/postgres /usr/local/var/postgres$OLD_POSTGRES_VERSION
mv /usr/local/var/postgres$NEW_POSTGRES_VERSION /usr/local/var/postgres
# Start service
brew services start postgresql
# Optimize new cluster
./analyze_new_cluster.sh
# Uncomment to cleanup old postgresql, not recommended before you have sufficient confidence on the DB upgrade
# brew cleanup
# rm -rf /usr/local/var/postgres$OLD_POSTGRES_VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment