Heroku transfer db from one app to another

its only 1 command to copy database from app to app now you don't have to backup:

heroku pg:copy app_name_to_copy_from::database_color_to_copy_from database_color_to_copy_to --app app_name_to_copy_to

check it here


If you look at heroku docs it says

PG Backups as an add-on has been deprecated. The commands exist as part of the Heroku Postgres namespace in the CLI. The new functionality is live and available for use.

So you can use the pgbackups functionality directly without having to add any add-ons

To create a backup you can run

 heroku pg:backups capture --app app_name

if you have multiple databases then you can specify database url like this

heroku pg:backups capture HEROKU_POSTGRESQL_PINK

To restore from a backup on another app you can run

heroku pg:backups restore b001 DATABASE_URL --app app_name

You can transfer database by

heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK_URL --app app_name

You can also upload your database to a public url and then use that url to import database on another app by

heroku pg:backups public-url b001 --app app_name

and then import it by

heroku pg:backups restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE -a app_name

If you are moving from one app to another and want to use same database for another app then you can follow these steps:

  • Login to your heroku account
  • Select your old app and go to settings tab
  • Reveal config vars for your old app
  • Copy DATABASE_URL
  • Go back and select your new app
  • Replace new apps DATABASE_URL with the old apps value

heroku pg:copy app1_name::HEROKU_POSTGRESQL_ONYX_URL HEROKU_POSTGRESQL_AQUA_URL --app app2_name

Where the second db url is on app2_name


I needed something slightly different so sharing it here:

heroku pg:copy name_of_app_being_copied::DATABASE_URL DATABASE_URL --app name_of_app_being_copied_to

Note: Both references to DATABASE_URL do not need to be changed. It may seem odd, but the first instance references the database url for the app being copied and the second one references the database url of the app being copied to.