8

I'd like to have my master Postgres DB, which is is hosted on Heroku, replicate down to a slave DB on my laptop. Is this possible?

Heroku's documentation talks about both master and slave hosted within Heroku: https://devcenter.heroku.com/articles/heroku-postgres-follower-databases

Someone else asked whether it's possible to have the master outside Heroku and a slave inside Heroku (it's not): Follow external database from Heroku

I haven't seen an answer for the reverse -- having the master in Heroku and the slave outside.

Why do I want this? To speed up development. With my app running locally and the DB in the cloud, the round-trip is long so data access is slow. Most data access is read-only. If I could have a local slave, it would speed things up significantly.

Related: what if my laptop is disconnected for a while? Would that cause problems for the master?

3 Answers 3

8

You cannot make a follower (slave) outside of the Heroku network – followers need superuser access to create, which Heroku Postgres doesn't provide you, so you are limited to running a follower on Heroku.

If you want to pull down a copy locally for use/inspection, you can do so with pgbackups: https://devcenter.heroku.com/articles/heroku-postgres-import-export

Sign up to request clarification or add additional context in comments.

Comments

2

I'd highly recommend the program Parity for this.

It copies down the last Heroku backup to your local machine with a nice command line interface:

development restore production

Comments

0

I'd rather just pull the production database's contents from Heroku every now and then.

$ heroku db:pull

You can speed that up with a rake task.

# lib/tasks/deployment.rake
namespace :production do
  desc 'Pull the production DB to the local env'
  task :pull_db do
    puts   'Pulling PRODUCTION db to local...'
    system 'heroku db:pull --remote MY_REMOTE_NAME --confirm MY_APP_NAME'
    puts   'Pulled production db to local'
  end
end

You can call rake production:pull_db to overwrite your local development database.

2 Comments

Don't use db:pull. It's been removed from the documentation (for Heroku Postgres). Use pgbackups and download a copy from there, or use pg_dump yourself.
Thanks for the note. I've been using this for a while and it might not be the most current way any more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.