Skip to content

Instantly share code, notes, and snippets.

@caioagiani
Forked from zulhfreelancer/upgrade.md
Created December 15, 2022 23:20
Show Gist options
  • Save caioagiani/cc2afbaa09957a61a9113fc20f01c855 to your computer and use it in GitHub Desktop.
Save caioagiani/cc2afbaa09957a61a9113fc20f01c855 to your computer and use it in GitHub Desktop.
How to upgrade Heroku Postgres database plan?
  1. Assuming you have multiple Heroku apps and Git remote like so:
development https://git.heroku.com/xxx.git (fetch)
development https://git.heroku.com/xxx.git (push)
origin      [email protected]:xxx/xxx.git  (fetch)
origin      [email protected]:xxx/xxx.git  (push)
production  https://git.heroku.com/xxx.git (fetch)
production  https://git.heroku.com/xxx.git (push)
staging     https://git.heroku.com/xxx.git (fetch)
staging     https://git.heroku.com/xxx.git (push)
  1. In this tutorial, I'm upgrading Hobby Basic plan to Standard 0 plan for my staging app.

List of Heroku Postgres plans

  1. Start with:
$ cd into/the/rails/project
  1. Turn on Maintenance Mode for your Heroku app:
$ heroku maintenance:on -r staging
  1. Login as owner of the app by doing:
$ heroku login
  1. Provision new database:
$ heroku addons:create heroku-postgresql:standard-0 -r staging && heroku pg:wait -r staging
  1. Check your Heroku web UI > app > Resources. You should see your new database with name pattern like this - Heroku Postgres :: XXX. Take the color after the :: and capitalize it. For example, I saw Heroku Postgres :: Amber and I should use AMBER in next step.

  2. Promote the new database to our Heroku app by taking the color from step 7 above and append it after HEROKU_POSTGRESQL_

$ heroku pg:promote HEROKU_POSTGRESQL_AMBER -r staging
  1. Copy old database to new database:
$ heroku pg:copy HEROKU_POSTGRESQL_COPPER HEROKU_POSTGRESQL_AMBER -r staging --confirm your-heroku-app-name

Note:

HEROKU_POSTGRESQL_COPPER is my old database. If you not sure what database color you old database is, refer step 7 again.

  1. Destroy old database:
$ heroku addons:destroy heroku-postgresql:hobby-basic -r staging
  1. Check your data:
$ heroku run console -r staging

> Cat.count
=> 1694
  1. Go to your Heroku app > Settings > Reveal Config Vars and make sure your old database color ENV variable is not there. For me, I can't see HEROKU_POSTGRESQL_COPPER_URL anymore and that's what I'm expecting. Only HEROKU_POSTGRESQL_AMBER_URL is there.

  2. Turn off the Maintenace Mode:

$ heroku maintenance:off -r staging
  1. Run heroku login command again to switch your Heroku CLI username. Otherwise, any deployment or changes you made after this will be tied to previous user (the user that do DB upgrade in steps above).

Done.

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