Owen Conti

How To Copy Heroku Postgres Database Across Environments

under Devops

If you find yourself needing to copy a database across environments (say production to staging) you can use this one line command from Heroku:

1heroku pg:backups:restore {original_env}::{backup_id} {DATABASE_URL} --app {new_env}


  • original_env is the name of the environment you are pulling the backup from
  • backup_id is the ID of the backup, found on the Durability tab of the Heroku Postgres database page
  • DATABASE_URL is the env var that Heroku generated for the new database
  • new_env is the new application ID that has the DATABASE_URL attached to ti

Thanks for reading this article!

Hopefully you found this article useful! If you did, share it on Twitter!

Found an issue with the article? Submit your edits against the repository.