wuliwong
wuliwong

Reputation: 4368

Using Heroku Postgres database locally in a Rails 3 app

I have downloaded the database from an existing Heroku app onto my local machine. The data I downloaded is in a single file; let's call it herokuapp.db. I also have Postgres installed and I can successfully create a new Postgres database and have my Rails app reference that. What I want to do is move the data I downloaded from Heroku into this database or create a new Postgres database using the downloaded data.

Upvotes: 1

Views: 529

Answers (2)

Powers
Powers

Reputation: 19328

I just solved the same problem with a similar technique that Will suggested (thanks Will!).

$ heroku pgbackups:capture
$ curl -o latest.dump `heroku pgbackups:url`
$ pg_restore --verbose --clean --no-acl --no-owner -d [database_name] latest.dump

The database_name can be found in the development section of the database.yml file.

EDIT
I recently performed this task again with Postgres.app and the last command above did not work. I was getting this error message:

pg_restore: connecting to database for restore
pg_restore: [archiver (db)] connection to database "[database_name]" failed: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
pg_restore: *** aborted because of error

Here is the updated command that worked:

$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $USER -d [database_name] latest.dump

Upvotes: 1

Will
Will

Reputation: 2961

Use pg_restore --verbose --clean --no-acl --no-owner -d [database_name] [herokuapp.db] see https://devcenter.heroku.com/articles/export-from-heroku-postgres for more information

Upvotes: 2

Related Questions