Last active
May 28, 2018 16:13
-
-
Save huangsam/96cd4e6e31fcdc64d0020d82ef5df777 to your computer and use it in GitHub Desktop.
Postgres 9.6 to 10.4 migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run postgres 9.6 | |
| docker exec -it db bash | |
| gosu postgres psql | |
| DB_STUFF=<<EOF | |
| CREATE DATABASE critical_app | |
| \c critical_app | |
| CREATE TABLE guestbook (visitor_email text, vistor_id serial, date timestamp, message text); | |
| INSERT INTO guestbook (visitor_email, date, message) VALUES ('jim@gmail.com', current_date, 'This is a test.'); | |
| INSERT INTO guestbook (visitor_email, date, message) VALUES ('bob@gmail.com', current_date, 'Another test.'); | |
| INSERT INTO guestbook (visitor_email, date, message) VALUES ('mary@gmail.com', current_date, 'Final test.'); | |
| SELECT visitor_email FROM guestbook; | |
| \q | |
| EOF | |
| gosu postgres pg_dumpall > /var/lib/postgresql/data/backup.sql | |
| exit | |
| # Move backup data out | |
| # Remove postgres 9.6 | |
| # Run postgres 10.4 | |
| # Move backup data in | |
| docker exec -it db bash | |
| gosu postgres psql -f /var/lib/postgresql/data/backup.sql postgres | |
| gosu postgres psql critical_app | |
| DB_STUFF=<<EOF | |
| SELECT visitor_email FROM guestbook; | |
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #docker run -d -v /home/samhuang/pgdata:/var/lib/postgresql/data --name db postgres:9.6 | |
| docker run -d -v /home/samhuang/pgdata:/var/lib/postgresql/data --name db postgres:10.4 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Followed this strategy: https://www.postgresql.org/docs/9.0/static/migration.html