til-jasontorres by Jason Torres

Heroku: Fastest Way to Copy Postgres Production Data to Staging

This is a commonly occuring theme for developers who need to debug

Copy the entire source database to the target database

heroku pg:copy source-app::DATABASE_URL DATABASE_URL --app target-app

This is destructive and will remove all your data so make sure to backup first!

This may take a while depending on the size of your database.

Forking postgres databases (same environment only)

An alternative option is forking the source data using pg:fork


heroku addons:create heroku-postgresql:standard-0 --fork DATABASE_URL --app target-app

For a fast option, use --fast

This only works for standard and premium plans.

Restoring backups from the source database to the target database

heroku pg:backups:restore source-app::b101 DATABASE_URL --app target-app

Posted: 31/5/2020