Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
(your database must exist before can do this)
@SubaruWRX55

This comment has been minimized.

Copy link

SubaruWRX55 commented Apr 4, 2013

what if my local is version 8 and heroku is using version 9?

@jensitus

This comment has been minimized.

Copy link

jensitus commented Apr 21, 2013

How about a local update?

@nmunson

This comment has been minimized.

Copy link

nmunson commented May 14, 2013

Thanks.

@enderahmetyurt

This comment has been minimized.

Copy link

enderahmetyurt commented Mar 15, 2014

Cheers mate.

@gobijan

This comment has been minimized.

Copy link

gobijan commented Jun 18, 2015

Worked great!

@dmilisic

This comment has been minimized.

Copy link

dmilisic commented Feb 3, 2016

Thanks.
I couldn't execute heroku pgbackups though, so I had to make the backup and download it via https://postgres.heroku.com/databases

Then, another problem arouse - my app wouldn't access the database (relation does not exist error or no schema has been selected to create in) and I had to run

grant usage on schema public to public;
grant create on schema public to public;

using psql, inside the database.

@Schwad

This comment has been minimized.

Copy link

Schwad commented Sep 22, 2017

Update: the command is now heroku pg:backups:capture

@Schwad

This comment has been minimized.

Copy link

Schwad commented Sep 22, 2017

And heroku pg:backups

@JouniorG

This comment has been minimized.

Copy link

JouniorG commented Dec 19, 2017

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.