Search code examples
databasepostgresqlherokutaps

Easy way to push postgres db to heroku in Win7? problems with db:pull and pg:transfer


Using Rails 3.2.2, finishing up my migration from sqlite to postgres 9.2. Used answer in this tutorial as a guide to install postgres and got stuck on Step 11 where it asks run heroku db:pull where I get:

Failed to connect to database: Sequel::AdapterNotFound -> LoadError: cannot load such file --pg

I dug deeper and found db:pull (taps gem) is deprecated and came across a few recommendations for pg:transfer. Installed pg:transfer, but I get the impression it may be *nix only(?) as if I run: heroku pg:transfer it returns:

Heroku client internal error. No such file or directory - .env (Errno:ENOENT)

If I do pg:transfer with -f and -t it gives me: 'env' is not recognized as an internal or external command, operable program or batch file which means it isn't bound to path or doesn't exist as a command in windows.

Any thoughts on above errors?


Solution

  • Resolved by using pg:backups gem, which was recommended as the replacement for taps in the Heroku docs. I used this guide and uploaded my dump to dropbox for Heroku to pick it up.

    Here's my exact list of steps and cmds:

    1. Added pgbackups from heroku.com add-ons to my instance.
    2. heroku pgbackups:capture DATABASE (this just backs up your heroku db)
    3. pg_dump -h localhost -U <pg username> -Fc dbname > dbname.dump
    4. Moved dbname.dump into a folder on my dropbox
    5. In Dropbox, right-click on dbname.dump => "Share link"
    6. Cancel the sharing dialogue pop-up, right-click on "Download button", Copy Link Address (Chrome)
    7. heroku pgbackups:restore DATABASE <paste dropbox download link here>

    Dropbox trickiness: don't use the file link provided by Dropbox since it's an html redirect and will cause pg:restore to fail, even though the extension ends in .dump

    Instead, navigate to your dropbox page and "right-click copy link address" on the Download button. That's the address you use in your pgbackups:restore (should be something like db.dump?token=<long random string>)

    A bit clunky, but got the job done. If you know a better way please let me know!