Wednesday, October 15, 2014

How to migrate from Heroku Shared-database to Dev or Basic Postgres

First, we installed the postgres add-on:
heroku addons:add heroku-postgresql:basic

When you run the command it created a new database:
Attached as HEROKU_POSTGRESQL_SOMECOLOR
You can see it by typing heroku config

Most of our apps were already running pgbackups:monthly (free), on one of them we ran:
heroku addons:add pgbackups

Put the app in maintenance mode:
heroku maintenance:on

Capture a backup of the current database:
heroku pgbackups:capture --expire
(Took under 2 minutes for a 12 MB database)

Now push that data into the new database:
heroku pgbackups:restore HEROKU_POSTGRESQL_SOMECOLOR

Now make the new database the current database:
heroku pg:promote HEROKU_POSTGRESQL_SOMECOLOR
(Replaces the heroku config variable DATABASE_URL with the URL for the new database. The old shared-database and it’s URL are still there, but they are not the default anymore.)

Check the new database is working:
heroku pg:psql HEROKU_POSTGRESQL_SOMECOLOR
=> select count(*) from users;
(To quit the CLI type \q )

Turn off maintenance mode:
heroku maintenance:off


Short steps ::

heroku pgbackups:capture --expire
heroku pgbackups:url
curl -o latest_dump_file.dump DATABASE_URL
heroku maintenance:on
heroku pgbackups:restore HEROKU_POSTGRESQL_WHITE_URL
heroku pg:promote HEROKU_POSTGRESQL_WHITE_URL
heroku pg:psq HEROKU_POSTGRESQL_WHITE_URL
heroku pg:psql HEROKU_POSTGRESQL_WHITE_URL
heroku maintenance:off

No comments:

Post a Comment