Skip to content

Instantly share code, notes, and snippets.

@joncode
Last active December 25, 2015 12:59
Show Gist options
  • Select an option

  • Save joncode/6980048 to your computer and use it in GitHub Desktop.

Select an option

Save joncode/6980048 to your computer and use it in GitHub Desktop.
changing databases heroku psql

go to heroku.com the site you are upgrading

  1. add the new database - we chose 'CRANE' for 50$ / month

     heroku addons:add heroku-postgresql:crane        
    
  2. in console

     heroku pg:wait --remote staging
     
     gives you a COLOR and tells you when new db is available
    
  3. stop app from creating new data

     we used a json response in JsonController 
    
     heroku recommends 
             heroku maintenance:on  --remote staging
             heroku ps:scale worker=0 --remote staging
    
  4. back up the current db

     heroku pgbackups:capture --expire --remote staging 
     
     dump it to local just in case 
     
             $ curl -o latest.dump `heroku pgbackups:url --remote staging` 
    
  5. restore the new db with the old databse data

     heroku pgbackups:restore HEROKU_POSTGRESQL_OLIVE --remote staging  --confirm dbappdev
             leave off  --confirm dbappdev and confirm at prompt 'dbappdev' 
    
  6. promote the new db to main db

     heroku pg:promote HEROKU_POSTGRESQL_OLIVE --remote staging
    
  7. check that heroku has correctly assigned DATABASE_URL

     heroku pg:info --remote staging 
     you will see (DATABASE_URL) next to the name of the new db
    
  8. reacivate the application

     heroku ps:scale worker=1 --remote staging
     heroku maintenance:off --remote staging
     
     re-commit code without JsonController down_for_maintenance
    
  9. delete the old database when convenient

     heroku addons:remove HEROKU_POSTGRESQL_COPPER --remote staging
    
@joncode
Copy link
Author

joncode commented Oct 14, 2013

here was the quick production list ... took 1-minute

gphm
heroku ps:scale worker=0 --remote heroku

heroku pgbackups:capture --expire --remote heroku
curl -o latest.dump heroku pgbackups:url --remote heroku
heroku pgbackups:restore HEROKU_POSTGRESQL_<!!HEROKU-COLOR> --remote heroku --confirm <!!SITE_NAME>
heroku pg:promote HEROKU_POSTGRESQL_<!!HEROKU-COLOR> --remote heroku
heroku pg:info --remote heroku

heroku ps:scale worker=1 --remote heroku
gphm

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