Skip to content

Instantly share code, notes, and snippets.

@wosephjeber
Last active November 26, 2020 23:03
Show Gist options
  • Save wosephjeber/d932d1d2a7016dbced9d82af87f629ba to your computer and use it in GitHub Desktop.
Save wosephjeber/d932d1d2a7016dbced9d82af87f629ba to your computer and use it in GitHub Desktop.
Upgrade from postgres 9.6.2 to 10.5 on OSX
## Following these commands should upgrade and migrate your existing database.
## This is an example of going from 9.6.2 to 10.5 on OSX.
## Be sure to update any version numbers based on the versions you're upgrading from and to.
## Adapted from https://stackoverflow.com/questions/24379373/how-to-upgrade-postgresql-from-version-9-6-to-version-10-1-without-losing-data
## Backup your database, just in case (replace databasename with your actual DB name)
pg_dump databasename > ~/Desktop/dev_dump
## Stop postgres
brew services stop postgresql
## Upgrade with Homebrew
brew update
brew upgrade postgresql
## Initialize a new 10.5 database
initdb /usr/local/var/postgres10.5 -E utf8
## run pg_upgrade (change
pg_upgrade -v -d /usr/local/var/postgres -D /usr/local/var/postgres10.5 -b /usr/local/Cellar/postgresql/9.6.2/bin/ -B /usr/local/Cellar/postgresql/10.5/bin/
## move data into new place
cd /usr/local/var
mv postgres postgres9.6.2
mv postgres10.5 postgres
## restart postgres
brew services start postgresql
@cleicar
Copy link

cleicar commented Nov 5, 2018

Thank you for this!

@pwichmann
Copy link

Can't you just run:
brew postgresql-upgrade-database
after line 15?

@kostikpl
Copy link

Can't you just run:
brew postgresql-upgrade-database
after line 15?

Works

@wosephjeber
Copy link
Author

Yeah, it’s much easier to upgrade Postgres now than it was when I wrote this gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment