Skip to content

Instantly share code, notes, and snippets.

@rtwomey
Created July 23, 2012 18:47
Show Gist options
  • Save rtwomey/3165360 to your computer and use it in GitHub Desktop.
Save rtwomey/3165360 to your computer and use it in GitHub Desktop.
How to migrate a DB on heroku to another plan

Recently, I had a staging database on Heroku that was running on the Ronin database (which was originally the lowest-sized DB you could get at Heroku). Since they added two new options, Crane and Kappa, we wanted to take advantage of the cost savings. Here's how you can migrate your Ronin DB to Crane (or any other plan).

The old database was named BROWN while the new one is CRIMSON. You can determine this by running:

heroku pg:info --app myapp-staging
  1. Add Crane database

     heroku addons:add heroku-postgresql:crane --app myapp-staging
     heroku pg:wait --app myapp-staging
    
  2. Turn on maintenance mode and capture a backup

     heroku maintenance:on --app myapp-staging
     heroku pgbackups:capture --expire --app myapp-staging
    
  3. Figure out what the name of the new database is

     heroku config --app myapp-staging | grep POSTGRESQL
    
  4. Restore the latest backup to the new database and verify it worked.

     heroku pgbackups:restore HEROKU_POSTGRESQL_CRIMSON --app myapp-staging
     heroku pg:psql HEROKU_POSTGRESQL_CRIMSON --app myapp-staging
     select count(*) from users;
     => 1
    
  5. Update the app to use the new database URL

     heroku pg:promote HEROKU_POSTGRESQL_CRIMSON --app myapp-staging
    
  6. Turn off maintenance mode:

     heroku restart --app myapp-staging
     heroku maintenance:off --app myapp-staging
    
  7. Verify everything worked the way you expect (i.e. create a new user):

     heroku pg:psql HEROKU_POSTGRESQL_CRIMSON --app myapp-staging
     select count(*) from users;
     => 2
    
     heroku pg:psql HEROKU_POSTGRESQL_BROWN --app myapp-staging
     select count(*) from users;
     => 1
    
  8. Remove the old database:

     heroku addons:remove heroku-postgresql:ronin --app myapp-staging
    

Check out the following sites for details

@rakibulislam
Copy link

Awesome tutorial. Just saved my day !

@PascalPixel
Copy link

Can you update this? Heroku docs are vague

@logicware
Copy link

We had a Standard 0 following a Premium 0. We have upgraded the Premium 0 to Premium 2. Now I want the Standard 0 to follow the new Premium 2 instead of the old Premium 0. I have made it un-follow the old master. But there seems to be no way to tell it to follow the new db. It seems that only way to create a follower is to do the following:

heroku addons:create heroku-postgresql:standard-2 --follow HEROKU_POSTGRESQL_CHARCOAL_URL (example from Heroku docs)

Can anyone help?

Thanks.

Matloob

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