Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active February 17, 2023 00:42
Show Gist options
  • Save zulhfreelancer/8d3ab87649372984ba0bba8efb067c46 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/8d3ab87649372984ba0bba8efb067c46 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.

@jackmoody11
Copy link

This is great! Thanks!

@bbelderbos
Copy link

This was really useful, thanks a lot

@GAKINDUSTRIES
Copy link

GAKINDUSTRIES commented Dec 28, 2017

Thanks man, you rocks 🚀

@jonmanes
Copy link

jonmanes commented Jan 8, 2018

Very helpful, thank you!

Copy link

ghost commented Jan 12, 2018

thanks that was so easy

@Z3nk
Copy link

Z3nk commented Feb 27, 2018

Thanks man !

@Agarwal17
Copy link

Very helpful.It saved my lot of time

@bookmebus
Copy link

short and easy to understand.

@nurhadimaulana2309
Copy link

Thanks! this is great! 👍

@hungmi
Copy link

hungmi commented Jul 8, 2018

Thanks!

@crova
Copy link

crova commented Jul 11, 2018

This helped me a lot a while back, and today I needed some references once more after a long time and it is really helpful indeed! Cheers

@Onikoroshi
Copy link

This was very helpful to me - thank you for taking the time to put it out here! However, I do have a couple of confusions that I hope someone can help me with:

  1. My current database doesn't seem to have a color. It just says "Heroku Postgres :: Database". What would be the HEROKU_POSTGRESQL_ bit for that?
  2. This is more of a frustration than anything else: Why in the wide world did Heroku make it so difficult just to change my payment plan? Why can't I just change it from the interface? Looking at the plan descriptions and such, all I see is the easing of certain limitations (10mil rows instead of 10k, etc), so why does it require a brand new database rather than just changing a couple of those settings?

@chill5018
Copy link

  1. My current database doesn't seem to have a color. It just says "Heroku Postgres :: Database". What would be the HEROKU_POSTGRESQL_ bit for that?

For this you can use the add-on name that you see in heroku pg:info --app your-app

So the command would look like:
heroku pg:copy postgresql-asymmetrical-123456 HEROKU_POSTGRESQL_AMBER --confirm your-app --app your-app

@hamley241
Copy link

Heroku by default creates latest version of Postgres that it supports, if you want to create specific version, you should be using something like this

heroku addons:create heroku-postgresql:standard-0 --version=9.5

@hasnatbabur
Copy link

How can I rename "HEROKU_POSTGRESQL_AMBER_URL" to "HEROKU_POSTGRESQL_URL"? I need plain env key names. Thanks

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