How to import heroku postgres locally from prod rails

1 Comment

Step 1: Setup Postgres locally and get working with your app.

Heroku db:pull only works if you have postgres setup locally on your machine.

Go here for some tips on how to do that.

Step 2: Find out your postgres database name.

Before you can run the db:pull command, you need to know what postgres calls your prod database.

Get the name of your app
$ heroku apps

Then get the name of your postgres instance
$ heroku addons –app yourappname | grep POSTGRES
heroku-postgresql:dev HEROKU_POSTGRESQL_ORANGE

Step 3: Export db from prod.

You are now ready to pull the db from prod. Note this is going to create a new local database (to ensure you don’t accidentally blow over anything).

$ heroku pg:pull HEROKU_POSTGRESQL_ORANGE –app

Step 4: Import locally.

Now you just need to point your local database.yaml file to the newly generated postgres instance just created.

  adapter: postgresql
  host: localhost
  encoding: unicode
  database: <newdatabase>
  pool: 5
  username: jrasmusson

Step 5: Voila! You are done.

Restart your web server, fire up your app, and you should now see prod data locally running on your box.

Have fun!

Links that help:

heroku db:pull no longer working – workaround

Leave a comment

I was disappointed when I discovered that the very handy heroku db:pull stop working for me after upgrading to Ruby 2.0 and Rails 4.0.

I got it going again – by basically reverting back to Ruby 1.9.3 and Rails 3.1.0.

Here are the steps on how to revert back with rvm.

$ rvm install 1.9.3
$ ruby -v
$ rvm use 1.9.3-p286
$ rvm gemset create rails310
$ rvm 1.9.3-p286@rails310
$ rails -v
$ gem install rails -v 3.1.0
$ rvm gemset list
$ heroku db:pull –app targetapp
$ gem install taps
$ gem install sqlite3
$ heroku db:pull –app targetapp

Voila! Done.

%d bloggers like this: