Computer Tips - Postgresql does not understand databases from previous versions

Date: 2011may25 Updated: 2020apr28 OS: Linux Keywords: postgresql, postgres Q. Postgresql does not understand databases from previous versions How can I upgrade PostgreSQL and keep my data? A. There is finally an easy command for this
postgresql-setup --upgrade
The OLD way... Before upgrading:
cd ~postgres pg_dump database1 > database1.sql (for all databases)
(you really should have other backups)
mv /var/lib/pgsql/data /var/lib/pgsql/data.old
... upgrade ... If you have Postgres 12.1+ upgrade your databases with:
postgresql-setup --upgrade
Otherwise, to restore your data after the upgrade:
cd ~postgres createdb database1 (for all databases) pg_restore -d database1 database1.sql
Then in file /var/lib/pgsql/data/pg_hba.conf I like to change "ident sameuser" to "trust"
# Strict local all all ident sameuser
# Slack local all all trust
To start the service:
postgresql-setup initdb (You have multiple backups, right!)
Or on older systems:
service postgresql initdb (You have multiple backups, right!) systemctl start postgresql
Or on older systems:
service postgresql start
I wish you didn't have to do all this. Mysql will read previous versions of the binary data.