Copy production data to staging

In this document we are assuming that the name of the application is wheel. The name of staging instance is wheel-staging and the name of production instance is wheel-production.

Find database url for each of the applications

Here is output of executing heroku config -a wheel-production.

DATABASE_URL:               postgres://xgummbtqualf:643a810372e8decc30a7e99f715df6495ea0a5640ffcb3271ab39adae30fa5@ec2-184-73-247-240.compute-1.amazonaws.com:5432/d4sua6eoj2tq


HEROKU_POSTGRESQL_ROSE_URL: postgres://xgummbtqualf:643a810372e8decc30a7e99f715df6495ea0a5640ffcb3271ab39adae30fa5@ec2-184-73-247-240.compute-1.amazonaws.com:5432/d4sua6eoj2tq

Notice that in the above case we see both DATABASE_URL and HEROKU_POSTGRESQL_ROSE_URL. Also notice that both of them have the same value. Names like DATABASE_URL or HEROKU_POSTGRESQL_ROSE_URL are just keys to the actual value. Some applications have names like HEROKU_POSTGRESQL_COBALT_URL.

In this example we will assume that production instance has ROSE name and the staging instance has COBALT name. Before executing the actual command please make the change in name as per the values in your application.

Copy production data to staging

Following code will copy data from production instance to staging instance. Don’t worry before the data is destroyed heroku will prompt you for confirmation.

heroku pg:copy wheel-production::HEROKU_POSTGRESQL_ROSE_URL HEROKU_POSTGRESQL_COBALT_URL -a wheel-staging