Postgresql - Migrate database after update

Siple way

brew postgresql-upgrade-database

Update brew and upgrade old packages.

brew update && brew upgrade

After running pg_ctl -D /usr/local/var/postgres restart i get message.

The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 12.4.

So we need upgrade old data to new version..

After upgrade postgresql v 11 has be gone. Install missing postgres version.

brew install postgresql@11

Create backup from old data.

mv /usr/local/var/postgres /usr/local/var/postgres.old

Init new database with correct encoding and locale.

initdb -E UTF8 --locale=C  /usr/local/var/postgres/

Run database upgrade

pg_upgrade -b /usr/local/Cellar/postgresql@11/11.9/bin -B /usr/local/Cellar/postgresql/12.4/bin/ -d /usr/local/var/postgres.old -D /usr/local/var/postgres