Skip to content

Instantly share code, notes, and snippets.

@anhkind
Last active August 16, 2022 11:16
Show Gist options
  • Save anhkind/e4bcde6a7bbd9f080cd6 to your computer and use it in GitHub Desktop.
Save anhkind/e4bcde6a7bbd9f080cd6 to your computer and use it in GitHub Desktop.
Heroku postgres: dump and restore
# Details: https://devcenter.heroku.com/articles/heroku-postgres-import-export
# Create postgres role (v13) if not existing yet
createuser -s postgres -U <os-username>
# Dump
heroku pg:backups capture
curl -o latest.dump `heroku pg:backups public-url`
# Restore to local db
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d mydb latest.dump
# Restore to another DB on Heroku (DATABASE_URL represents the HEROKU_POSTGRESQL_COLOR_URL on the app-2)
heroku pg:backups restore `heroku pg:backups public-url -a app-1` DATABASE_URL -a app-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment