Maintaining Multiple Postgres Version
Sometimes we need to have different Postgres versions in our local machine. We just need to know the port the versions are running and we are good to go.
For this let's install two versions of Postgres 9.6 and 11 via commands
Install Postgres 9.6
sudo apt-get install postgresql-9.6
Install Postgres 11
sudo apt-get install postgresql-11
Lists the postgres clusters
pg_lsclusters
start-stop the clusters
sudo pg_ctlcluster 9.6 main startsudo pg_ctlcluster 9.6 main stopsudo pg_ctlcluster 11 main startsudo pg_ctlcluster 11 main stop
connects to 9.6
sudo -i -u postgres psql -p 5432
connects to 11
sudo -i -u postgres psql -p 5433
By changing the port only we can restore and dump db according to postgres version
dumps and restores 9.6
pg_dump --host localhost --port 5432 --username "postgres" --encoding UTF8 --verbose --file "{{db_backup_path}}" "{{db_name}}"pg_restore --host 127.0.0.1 --port 5432 --username "postgres" --dbname "{{db_name}}" --verbose "{{db.backup}}"
dumps and restores 11
pg_dump --host localhost --port 5433 --username "postgres" --encoding UTF8 --verbose --file "{{db_backup_path}}" "{{db_name}}"pg_restore --host 127.0.0.1 --port 5433 --username "postgres" --dbname "{{db_name}}" --verbose "{{db.backup}}"
Top comments(1)
Subscribe

⚡ Nirazan Basnet ⚡•
Exploring the new tools and techniques on frontend development. Loves to meet up with new people and participate in the community. I do interesting stuff on codepen https://codepen.io/nirazanbasnet
- Email
- LocationKathmandu, Nepal
- EducationBe IT
- Joined
Great !!
For further actions, you may consider blocking this person and/orreporting abuse