Skip to content

Instantly share code, notes, and snippets.

@kostikpl
Last active January 29, 2018 21:01
Show Gist options
  • Save kostikpl/bbb2be4a4890d8d4a5b313c4fc6cddb1 to your computer and use it in GitHub Desktop.
Save kostikpl/bbb2be4a4890d8d4a5b313c4fc6cddb1 to your computer and use it in GitHub Desktop.
major version postgres update via brew

Accidentally update all brew packages, including PG. I find missing pg connection through ps aux | grep sql Also I recognize in brew services that PG status is "started" but writen in yellow. brew services list After I check PG log to be ensure PG was updated less /usr/local/var/log/postgres.log Here's steps how to fix this.

$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ brew services stop postgresql
// unloadning
$ mv /usr/local/var/postgres /usr/local/var/postgres_old
// copy old BD's so we can recover later
$ psql --version
psql (PostgreSQL) 10.1 //checking current version
$ cat /usr/local/var/postgres_old/PG_VERSION
9.6 // checking old version
$ initdb /usr/local/var/postgres -E utf8
// creating new DB with new version
$ cat /usr/local/var/postgres/PG_VERSION
10
$ ls /usr/local/Cellar/postgresql
10.1  9.6.3 // we need this versions to recover old DBs
$ pg_upgrade -b /usr/local/Cellar/postgresql/9.6.3/bin -B /usr/local/Cellar/postgresql/10.1/bin -d /usr/local/var/postgres_old -D /usr/local/var/postgres

lc_collate values for database "postgres" do not match:  old "C", new "en_US.UTF-8"
Failure, exiting

In my case I face 2 errors migrating to new version. Solution

$ rm -fr /usr/local/var/postgres
$ initdb /usr/local/var/postgres --lc-collate=C --lc-ctype="UTF-8"
// re-initing DB with propper keys and encoding
$ pg_upgrade -b /usr/local/Cellar/postgresql/9.6.3/bin -B /usr/local/Cellar/postgresql/10.1/bin -d /usr/local/var/postgres_old -D /usr/local/var/postgres
// one more time trying recover all DBs

If everything is ok

$ brew services start postgresql
$ rm -fr /usr/local/varpostgres_old
// removing old PG files

Should be alright

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