How do I upgrade postgresl database? Incompatibility error

Solution 1:

For me on OS X with Homebrew it was like this.

  1. Installed new postgres with Homebrew (started getting the error)
  2. mv /usr/local/var/postgres /usr/local/var/postgres.old
  3. initdb -D /usr/local/var/postgres
  4. pg_upgrade -b /usr/local/Cellar/postgresql/9.0.4/bin -B /usr/local/Cellar/postgresql/9.1.2/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres
  5. ./delete_old_cluster.sh (this script is created for you automatically in current dir when you go through above steps)
  6. rm delete_old_cluster.sh

Solution 2:

If you’re on macOS and installed Postgres via Homebrew you can simply run:

brew postgresql-upgrade-database

This will ensure that the old Postgres version is installed, create a new database, and then migrate it via pg_upgrade. The old data will remain in /usr/local/var/postgres.old.

Solution 3:

Here's how I did it on fedora:

  • rename your old data directory to something like data.old
  • run postgresql-setup initdb this will create a new data directory
  • then run pg_upgrade -b /usr/lib64/pgsql/postgresql-9.0/bin/ -B /usr/bin/ -d data.old/ -D data

I think for you that would be:

pg_upgrade -b /usr/local/Cellar/postgresql/9.0.4/bin -B /usr/bin/ -d /usr/local/var/postgres.old/ -D /usr/local/var/postgres/
  • you also want to copy pg_hba.conf and postgresql.conf from data.old to the new data directory.
  • restart postgresql

Solution 4:

I missed/forgot the "initdb" line

initdb -D /usr/local/var/postgres

After the DB was created, the pg_upgrade worked on my windows system.