How to upgrade PostgreSQL from 9.5 to 9.6.1 without losing data?
After 9 months, I updated to PostgreSQL 10 from 9.6.5 with
1) Stop postgresql:
brew services stop postgresql
2) Initialize postgresql10 database:
initdb /usr/local/var/postgres10.0 -E utf8
3) Double check the newly created db:
4) Run pq_upgrade to move data to new database:
pg_upgrade \ -d /usr/local/var/postgres \ -D /usr/local/var/postgres10.0 \ -b /usr/local/Cellar/postgresql/9.6.5/bin/ \ -B /usr/local/Cellar/postgresql/10.0/bin/ \ -v
5) Rename old database:
mv /usr/local/var/postgres /usr/local/var/postgres9.6.5
6) Rename new database to postgres:
mv /usr/local/var/postgres10.0 /usr/local/var/postgres
7) Restart postgresql:
brew services start postgresql
If your database size is not large, you can use pg_dump and pg_dumpall to take database structure and data dump in the form of sql queries from posgtres 9.5 and restore the same in postgres 9.6.1.
If the database size is too large, then go for pg_upgrade. By looking at the error, it seems the user does not have permissions on the directory and not able to write in the log file. Also to save time, i would suggest you use
-k option of pg_upgrade for faster upgrade. Note that
-k will create soft links of your old data in Newly installed data directory. So you will not be able to delete old data.