Copy database to review app


I'd like to copy a staging/production database to my review apps on creation.


Our advice in is:

Copying full database contents from parent to Review apps (similar to heroku fork) is not currently supported. Copying production data to test apps means the risk of data leaks or other programming mistakes operating on recent customer data. For those reasons, we instead recommend seeding databases comprehensively with non-production data using seed scripts run with the postdeploy command.

However, a few workarounds are as follows:

  • Attach your staging database to Review Apps using heroku addons:attach, if no destructive actions (such as database migrations) will run as part of your Review Apps checks or deployments

  • Copy the latest backup of your staging database to your Review App database, using heroku pg:backups:restore or even curl <review app pg backup url> | pg_restore --verbose --clean --no-acl --no-owner --dbname $DATABASE_URL in a postdeploy script.

You can run these commands from your computer, and also through a one-off dyno where you will need to install the Heroku CLI first. To do so you can try this unofficial buildpack:

Another option to run these tasks is to use the release phase which runs after the app is deployed:

We recommend only doing this when you can ensure that your staging database contains a safe set of data and not a production fork, so that the worries around data leaks are lessened.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support