Issue
I need to recover a recently deleted production-tier (Standard/Premium/Private/Shield) Heroku Postgres database.
Resolution
If you've deprovisioned your database by mistake and need to recover it, you may be able to restore it within the stated continuous protection rollback period.
To do so:
- Identify the release of your app when the database was detached. Use
heroku releases --app <APP_NAME>and find the release reflecting theDETACHevent of the database you deleted. Use the version of the release prior to this one in step 2. - Get the old database URL for the deleted database from the config vars of that release. To do so, run
heroku releases:info <releaseversion> --app <APP_NAME>and copy the database URL for the database. This URL will be used in step 3. - Create a new database with
heroku addons:create heroku-postgresql:<plan> --as RECOVERED_DATABASE --app <APP_NAME> -- --fork <old-database-url>. - Wait for the database to become available with
heroku pg:wait --app <APP_NAME>.
As an alternative recovery method, you can also check if your app still keeps any Heroku PGBackups from your deleted database to restore it. Use heroku pg:backups --app <APP_NAME> to check the existing PGBackups associated to your app.