Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active May 6, 2021 14:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zulhfreelancer/221e375b532d1a1c9b773ebe6b363d68 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/221e375b532d1a1c9b773ebe6b363d68 to your computer and use it in GitHub Desktop.
How to export Heroku Postgres Database to Localhost Database (Rails)?

How to export Heroku Postgres Database to Localhost Database (Rails)?

Step 1

$ cd /path/to/your/rails/app
$ heroku pg:backups capture
$ curl -o latest.dump `heroku pg:backups public-url`

OR

$ curl -o latest.dump `heroku pg:backups public-url --remote <your_remote_name>`

Step 2

Enter app/config/database.yml. Copy your localhost database name.

Example:

development:
  adapter:    postgresql
  database:   YOUR_DATABASE_NAME_HERE
  pool:       5
  timeout:    5000

Step 3

$ rake db:drop db:create db:migrate
$ pg_restore -O -d YOUR_DATABASE_NAME_HERE -c -n public -v latest.dump

OR

$ rake db:drop db:create db:migrate && pg_restore -O -d YOUR_DATABASE_NAME_HERE -c -n public -v latest.dump

Reference: Heroku


Copying Your Production Database to Staging on Heroku

heroku pg:backups restore `heroku pg:backups public-url --app production-app-name` DATABASE --app staging-app-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment