Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a plain text postgres database dump on heroku?

Due to version incompatibilities of my postgres database on heroku (9.1) and my local installation (8.4) I need a plain text sql database dump file so I can put a copy of my production data on my local testing environment.

It seems on heroku I can't make a dump using pg_dump but can instead only do this:

$ heroku pgbackups:capture $ curl -o my_dump_file.dump `heroku pgbackups:url` 

...and this gives me the "custom database dump format" and not "plain text format" so I am not able to do this:

$ psql -d my_local_database -f my_dump_file.sql 
like image 264
user1187534 Avatar asked Apr 05 '14 22:04

user1187534


People also ask

How do I read Heroku database?

You can find them by visiting the Resources tab on your Dashboard then clicking on the DB you use. It will take you to the Addons page in another tab. Click on the Settings tab then View Credentials. Using these credentials, you can use Adminer to login to the DB.


1 Answers

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:[email protected]: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 
like image 162
Alex Avatar answered Sep 20 '22 16:09

Alex