1) Identify the Source PostgreSQL Version:
First, determine the PostgreSQL version and port that the database is currently running on:
$ pg_lsclusters
2) Backup the Database:
$ pg_dump -U USER -h localhost -p SOURCE_PORT -Fc DB_NAME > db_backup.dump
Create a new database in the new PostgreSQL version
1) Create a New Database:
- Connect to the postgresql:
$ sudo -u postgres psql -p NEW_PORT
Then run:
CREATE DATABASE new_database_name WITH TEMPLATE = template0;
\connect new_database_name
CREATE EXTENSION postgis;
2) Restore the Backup:
Use the pg_restore command to restore the database from the backup file, specifying the target database and required connection parameters:
$ pg_restore -U USER -h localhost -p NEW_PORT -d new_database_name db_backup.dump