Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

YoungInnovations profile imageManish Pradhan
Manish Pradhan forYoungInnovations

Posted on

     

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
Enter fullscreen modeExit fullscreen mode

Install Postgres 11

sudo apt-get install postgresql-11
Enter fullscreen modeExit fullscreen mode

Lists the postgres clusters

pg_lsclusters
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

connects to 9.6

sudo -i -u postgres psql -p 5432
Enter fullscreen modeExit fullscreen mode

connects to 11

sudo -i -u postgres psql -p 5433
Enter fullscreen modeExit fullscreen mode

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}}"
Enter fullscreen modeExit fullscreen mode

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}}"
Enter fullscreen modeExit fullscreen mode

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
nirazanbasnet profile image
⚡ 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

Great !!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp