Upgrade Postgres version from 9.6 to 11

Based on this stackoverflow thread

  1. Make a dump: pg_dumpall | xz -9 > ./dumpall.sql.xz
  2. Install a new version of db
  3. pg_lsclusters should show an old and a new cluster running together
  4. Drop the new cluster: sudo pg_dropcluster 11 main --stop
  5. Stop database server: sudo systemctl stop postgresql
  6. Make one more backup just in case: sudo tar cfJ ./backup.tar.xz /var/lib/postgresql/9.6/main
  7. Upgrade the old cluster: sudo pg_upgradecluster -m upgrade 9.6 main
  8. Start the server: sudo systemctl start postgresql
  9. pg_lsclusters should show the old cluster is down and the new one is online
  10. If everything works ok, remove the old cluster: sudo pg_dropcluster 9.6 main --stop