Last active
July 25, 2022 20:16
-
-
Save cjolly/2870054 to your computer and use it in GitHub Desktop.
Use homebrew to upgrade to postgres on OSX
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
newpg=9.6.1 # set to new PG version number | |
oldpg=`pg_config --version | cut -d' ' -f2` | |
# PG 96. upgrades the readline to v7, which breaks anything linked against readline v6, like ruby via ruby-build. | |
# I *think* this should prevent it from installing v7. But if weird shit happens with various rubies, | |
# you'll have to reinstall them. | |
brew pin readline | |
# Stop current Postgres server | |
brew services stop postgresql | |
# Backup current db | |
mv /usr/local/var/postgres/ /usr/local/var/postgres-$oldpg | |
# Homebrew | |
brew update | |
brew upgrade postgresql | |
# Create new DB | |
initdb /usr/local/var/postgres -E utf8 | |
# Upgrade old DB to new DB | |
mkdir -p /tmp/pgupgrade && cd $_ | |
pg_upgrade \ | |
--old-datadir=/usr/local/var/postgres-$oldpg/ \ | |
--new-datadir=/usr/local/var/postgres \ | |
--old-bindir=/usr/local/Cellar/postgresql/$oldpg/bin \ | |
--new-bindir=/usr/local/Cellar/postgresql/$newpg/bin \ | |
--jobs=4 | |
# Start new Postgres server | |
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist | |
brew services start postgresql | |
# Clean new DB | |
./analyze_new_cluster.sh | |
# Make sure all your shit works! | |
# After determining upgrade successful you can remove old DB. | |
./delete_old_cluster.sh | |
brew cleanup postgresql | |
# Go home | |
cd ~ |
Awesome... this worked very well! And I have no idea what I'm doing with Postgres.. not sure how one would upgrade without such clear instructions.
nice, thanks.
When upgrading from 9.0 to 9.2, I had to specify the new version of pg_upgrade, eg. /usr/local/Cellar/postgresql/9.2.3/bin/pg_upgrade . . .
homebrew had issues with the upgrade
command; It told me that links with various names (various pg binary files) already exist. brew link --overwrite postgres
fixed the problem.
I updated the script to be a bit more dynamic based on your suggestions, thanks guys!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very useful, thanks!