Upgrade hobby-dev to hobby-basic on Heroku - heroku

I'm still getting my head wrapped around Heroku's plans. But I know I'm going to have around 3M rows in the db so I need to upgrade from hobby-dev to hobby-basic.
However, I can't find any documentation or help about this level of upgrade. Only docs to go from Hobby to Standard.
Do I need to create a new PG Add-On and then wipe out my hobby-dev db?

This answer assumes that you're using Heroku CLI. Any instance of "YOUR_APP_NAME" in a command should be replaced by the application name of the Heroku App you're working with.
You will also need on hand the connection URL (shown here as DATABASE_URL) of your current hobby-dev database to be upgraded.
1. Provision a new hobby-basic database:
heroku addons:create heroku-postgresql:hobby-basic -a YOUR_APP_NAME
This will output a name for the new database containing a color. You will need to refer to this later. For example:
HEROKU_POSTGRESQL_PINK_URL
2. Optionally put db into maintenance mode to ensure that no data is added to the db while it's being copied.
heroku maintenance:on --app YOUR_APP_NAME
3. Copy the existing hobby-dev db to the hobby-basic db
heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
Heroku will now print the following message.
heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
! WARNING: Destructive Action
! Transfering data from DATABASE_URL to HEROKU_POSTGRESQL_PINK
! This command will affect the app: YOUR_APP_NAME
! To proceed, type "YOUR_APP_NAME" or re-run this command with --confirm YOUR_APP_NAME
YOUR_APP_NAME
4. Confirm db transfer by typing the actual name of your application
YOUR_APP_NAME
5. Promote your new database
heroku pg:promote HEROKU_POSTGRESQL_PINK --app YOUR_APP_NAME
The color-based name of the database you promote should be copied from the output you got up in step 1. Do not copy and paste the line above word for word, it will not work.
6. If you put your db into maintenance mode earlier, turn it off.
heroku maintenance:off --app YOUR_APP_NAME

Related

How to back up Heroku pg database from app itself?

From a remote shell, using the Heroku toolbelt, it's pretty easy to trigger a db backup with:
heroku pg:backups:capture --app my-app
But how can I do that from a script running on the app itself? Something triggered from the heroku scheduler or manually like:
heroku run node myScript.js --app my-app
I have psql available so maybe that's an option although I don't know where to write to.
I don't see a way to do this via API here: https://devcenter.heroku.com/articles/platform-api-reference

Copy production database to staging heroku

How can I pull my production database to my staging server on heroku?
I have two remotes, production and staging.
From the documentation it appears that I want to run heroku pg:copy COBALT GREEN --app sushi but it isn't clear what all the arguments mean. How can I copy my production database to my staging database?
First use:
heroku pg:info -a your_production_app
to retrieve the name of the environment variable that has the URL of your production db, e.g HEROKU_POSTGRESQL_WHITE_URL.
Then:
heroku pg_info -a your_staging_app
to get the same for your staging app (e.g. DATABASE_URL).
Finally:
heroku pg:copy your_production_app::HEROKU_POSTGRESQL_WHITE_URL DATABASE_URL -a your_staging_app
Just to add a clarification to the #Yoni Rabinovitch's answer.
I do not have named database so I needed to replace name with DATABASE_URL instead. It is not much intuitive to duplicate DATABASE_URL, is it?
So instead of:
heroku pg:copy your_production_app::HEROKU_POSTGRESQL_WHITE_URL DATABASE_URL -a your_staging_app
I used
heroku pg:copy your_production_app::DATABASE_URL DATABASE_URL -a your_staging_app
Hope this might help somebody.

How to restore database from one heroku to another heroku database

I have two Heroku application in that from one heroku application - I take a dump. Now I want to restore that database to another heroku application. so How Can I do that?
I try this :
heroku pgbackups:restore HEROKU_POSTGRESQL_GREEN_URL "URL" --APP
When I run above command then
HEROKU_POSTGRESQL_COLOR_URL <---restore--- b013.dump
Retrieving... done
Restoring... done
then after when I am checking the database then No records display in the table.
All table records are blank
So What Should I do?
Please Help Me, Thanks In Advance
Heroku has step by step documentation on how to do this:
Heroku Dev Center: Using PG Backups to Upgrade Heroku Postgres Databases
Heroku has recently changed their commands around, here is the newest version of how to do it.

Transfer heroku database from one bamboo app to another cedar app

Is there a faster way to transfer database on one app to another, without using capture and restore process which is taking 3hrs in my case.
We are trying to move to Cedar app and can't afford a 3hrs downtime.
Is it possible to:
1. create a follower on current prod app
2. allow to catch up.
3. maintenace on
4. unfollow the follower on current prod app that I created on step 1
5. Promote that follower to another app.
6. maintenance off
Similar to this link: https://devcenter.heroku.com/articles/fast-database-changeovers
but trying to promote it to another app.
Is it possible?
Regards
If you are on one of the production plans for your database, you're in luck. There is a secret flag that you can use. It doesn't work for the dev plans, only crane and above. If your Bamboo app has a crane or better database, you can create a fork of it by grabbing the DATABASE_URL, and then running:
heroku addons:add heroku-postgresql:crane --fork="<PASTE DATABASE_URL HERE>" --app your-cedar-app
Or if you prefer, for minimal downtime using a procedure similar to our fast changeover:
heroku addons:add heroku-postgresql:crane --follow="<PASTE DATABASE_URL HERE>" --app your-cedar-app
heroku pg:wait --app your-cedar-app # let the new database boot
heroku pg:info --app your-cedar-app # Make sure it's caught up, Behind By should be =~ 0.
heroku maintenance:on --app your-cedar-app
heroku pg:unfollow HEROKU_POSTGRESQL_<color of new database> --app your-cedar-app
heroku pg:promote HEROKU_POSTGRESQL_<color of new database> --app your-cedar-app # make it the primary
heroku maintenance:off --app your-cedar-app

How can I pull an existing heroku app to new location for development?

I currently have the latest version of my code on another computer that I want to develop from (Home computer and laptop for when I'm out and about) I set up heroku for my app on my laptop. Now I need to associate my code on my desktop so that I can push to heroku from there as well.
This is what I get from my desktop:
desktop:~/NetBeansProjects/onlinescheduler$ git pull heroku master
fatal: 'heroku' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
I can't do heroku create because that will create a separate app. How do I associated the existing code with (or pull down a brand new version from) heroku?
Whats the command to do this?
Also, If you've never used heroku before on the other machine, you'll need to do a few more things first:
$ gem install heroku
$ heroku login
[then enter your credentials]
$ heroku keys:add [path to keyfile]
Now you can clone the remote repository:
$ git clone git#heroku.com:<heroku_app>.git <local_directory>
First of all, you'll want to follow the Quick Start instructions for Heroku, which you can get straight from the horse's mouth, right here: https://devcenter.heroku.com/articles/quickstart
Once you've gotten through step 3, come back here.
Then, you can type this into the command line:
heroku git:clone -a myapp
This is described here:
https://devcenter.heroku.com/articles/git-clone-heroku-app
Then, if you want to grab the database too, here are some options.
Newer Heroku instructions on import/export:
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Older heroku instructions on push and pull: https://blog.heroku.com/archives/2009/3/18/push_and_pull_databases_to_and_from_heroku
If you are using mongo, this is a useful tool to sync your mongo database: https://github.com/pedro/heroku-mongo-sync#readme
If you first need to get the app from Heroku, clone your app.
To do that, write in your Terminal:
heroku git:clone -a your_app_name
If you already have the app and the remote to heroku follow the next steps. If not, you can check instructions here https://devcenter.heroku.com/articles/git
Find the name of your database
Write in your Terminal:
heroku pg:info -a your_app_name
it will look something like this:
HEROKU_POSTGRESQL_MAROON_URL
Find the name of your local database
In your Rails app go to config/database.yml
it will look something like this:
your_app_name_development
Clone your production database (PostgreSQL)
Write in your Terminal with your own database names:
heroku pg:pull HEROKU_POSTGRESQL_MAROON_URL your_app_name_development -a your_app_name
HEROKU_POSTGRESQL_MAROON_URL is an example of how could be the name of your production database (in Heroku):
my_app_name_development is the name of your development database (locally)
the_name_of_my_app is the name of your app in Heroku
Don't forget to finish this with bundle install...
If you already have your code base ready and have heroku setup, use:
$ heroku git:remote -a your_heroku_app
This will allow you to deploy from your new location.
Reference: https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
Once you create a key in a new computer, you have to upload your new SSH key by typing heroku keys:add.

Resources