Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres copy Heroku Production DB to local development DB

I have a heroku database, d76mj7ltuqs.

I then have a local database, test_development.

The schema is the same on both of these databases - I want to pull all of the data from my production database and overwrite my local database, so that local is an exact replica of production at the time of pull.

How can I do that in Postgres?

like image 593
Luigi Avatar asked Apr 15 '14 15:04

Luigi


People also ask

When using the PG upgrade to upgrade to version 13 how much app downtime is required?

If no --version flag is set, the upgrade will default to 14. Performing a pg:upgrade requires app downtime on the order of 30 minutes.


2 Answers

Use heroku's "pg:pull":

You'll need to clear your local DB:

rake db:drop 

Then collect some information from Heroku:

heroku pg:pull DATABASE_URL test_development 

This will connect to the heroku DB, and copy it to the local database.

See Heroku's documentation on pg:pull for more details.

like image 159
JezC Avatar answered Sep 18 '22 23:09

JezC


clean your local database:

rake db:schema:load 

dump your heroku database:

heroku pg:backups:capture -r <**your production git repo name**> heroku pg:backups:download -r <**your production git repo name**> 

load data in your local database

pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <**test database name**> latest.dump 
like image 36
Montells Avatar answered Sep 22 '22 23:09

Montells