Skip to content

Instantly share code, notes, and snippets.

@huangsam
Last active May 28, 2018 16:13
Show Gist options
  • Select an option

  • Save huangsam/96cd4e6e31fcdc64d0020d82ef5df777 to your computer and use it in GitHub Desktop.

Select an option

Save huangsam/96cd4e6e31fcdc64d0020d82ef5df777 to your computer and use it in GitHub Desktop.
Postgres 9.6 to 10.4 migration
# 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
#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
@huangsam
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment