How to push a Postgres database to your Heroku app

This is a pretty simple process if you have all the gems you need.

Heroku uses the taps gem to upload a Postgres database to your server.

But why?

You have a local Postgres database that’s ready to go and you want your server to have the same database.

Step #1

Install the required gems:
[cc lang="bash" width="700" nowrap="false"]
gem install taps pg heroku
[/cc]

(You probably already had the heroku gem installed)

Step #2

Push the local database to production:

[cc lang="bash" width="700"]
[etagwerker@gesell censo2010]$ heroku db:push postgres://username:password@localhost/censo –app censo
[/cc]

You will see a dialog:

[cc lang="bash" width="700"]
Loaded Taps v0.3.23
Warning: Data in the app ‘censo’ will be overwritten and will not be recoverable.
!    WARNING: Potentially Destructive Action
!    This command will affect the app: censo
!    To proceed, type “censo” or re-run this command with –confirm censo
[/cc]

Step #3:

Confirm and watch your database get uploaded:
[cc lang="bash" width="700"]
Sending schema
Schema:        100% |==========================================| Time: 00:00:01
Sending indexes
departamentos: 100% |==========================================| Time: 00:00:12
Sending data
1 tables, 53,021 records
departamentos:  42% |=================                         | ETA:  00:04:49
[/cc]

Step #4:

Enjoy!

Update

There seems to be a problem with Taps and Heroku. I recently reported it here: Bug.

I was instructed (by Heroku support) to follow a different approach using Postgres dumps and Heroku restore.

Here it is.

1. Add the pgbackups add-on: http://addons.heroku.com/pgbackups (several free options)

2. Dump your local database using the pg_dump tool: http://www.postgresql.org/docs/8.4/interactive/backup-dump.html

3. Upload the dump file somewhere publicly accessible like S3, Dropbox, or your own private fileserver

4. Import from the dump file: http://devcenter.heroku.com/articles/pgbackups#importing_from_a_backup

I hope this helps.

About these ads