Skip to content

Instantly share code, notes, and snippets.

@nelldnine
Created November 20, 2017 06:35
Show Gist options
  • Save nelldnine/14cbe7cd05dcd6ef83ec1e7bab9f432f to your computer and use it in GitHub Desktop.
Save nelldnine/14cbe7cd05dcd6ef83ec1e7bab9f432f to your computer and use it in GitHub Desktop.
Heroku pg_dump
You could just make your own pg_dump directly from your Heroku database.
First, get your postgres string using `heroku config:get DATABASE_URL`.
Look for the Heroku Postgres url (example: `HEROKU_POSTGRESQL_RED_URL: postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398`), which format is `postgres://<username>:<password>@<host_name>:<port>/<dbname>`.
Next, run this on your command line:
pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<dbname> > output.sql
The terminal will ask for your password then run it and dump it into output.sql.
Then import it:
psql -d my_local_database -f output.sql
https://stackoverflow.com/a/22896985/4148220
@coolaj86
Copy link

Since search landed me here when I was trying to figure out "Heroku Postgres" vs "Native Postgres" import/export stuff, I figured I'd drop this for others who land here trying to figure out the same.

Instructions and scripts for backing up (anywhere) and restoring to Heroku later:
(for something more like $7/month rather than $200+/month)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment