Obromios
Obromios

Reputation: 16383

initb fails for brew postgresql-upgrade-database

I am using brew postgresql-upgrade-database to upgrade postgresql from 11.8 to 12 and migrate the data. The process failed with the following output

Upgrading postgresql data from 11 to 12...

Stopping postgresql@11... (might take a while) ==> Successfully stopped postgresql@11 (label: homebrew.mxcl.postgresql@11) waiting for server to shut down.... done server stopped ==> Moving postgresql data from /usr/local/var/postgres to /usr/local/var/postgres.old... ==> Creating database... Error: Upgrading postgresql data from 11 to 12 failed! ==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres... Error: Failure while executing; /usr/local/Cellar/postgresql/12.4/bin/initdb --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --lc-messages=en_US.UTF-8 --lc-monetary=en_US.UTF-8 --lc-numeric=en_US.UTF-8 --lc-time=en_US.UTF-8 -E\ UTF8 /usr/local/var/postgres exited with 1.

How do I fix this?

Upvotes: 1

Views: 1660

Answers (1)

Obromios
Obromios

Reputation: 16383

There is an [issue][1] using brew postgresql-upgrade-database. I will update this answer when the issue is resolved.

As at July 21, 2021 this issue is still open. My workaround is below:

WARNING this will wipe out your databases so they have to be reloaded or re-initialized.

brew uninstall --force postgresql
brew install postgresql@12
cd /usr/local/var/
rm -rf postgres
initdb /usr/local/var/postgres

When doing the brew install read the post install message and make sure that you have the correct paths etc in your .zshrc (or equivalent file e.g. .bashrc). If you do not have this set your path correctly, the initdb command may work. [1]: http://github.com/Homebrew/homebrew-core/issues/60686

Upvotes: 1

Related Questions