7

I've downloaded the latest copy of my heroku database with

$ curl -o latest.dump `heroku pg:backups public-url --app myapp`

And this gives a file with the following type on my local machine:

$ file db/latest.dump
    db/latest.dump: PostgreSQL custom database dump - v1.12-0

I'm trying to import this into my local Postgres DB (my_db) using psql. However, I'm getting lots of errors:

$ psql my_db < db/latest.dump
    ...
    psql:db/latest.dump:119425: invalid command \?A~??ܣb?{#?+????LS??
    psql:db/latest.dump:119426: invalid command \D%!ѡ/F??g????A???dC????|2?M?$?8GTJ??c?E?;??֛Sh??S?[NP?f?2?+H?W????k
    ... [thousands of lines]
    psql:db/latest.dump:261719: ERROR:  invalid byte sequence for encoding "UTF8": 0xba

The command psql -f db/latest.dump my_db fails the same way.

What needs to be done in order to import this file locally into a new database with the same schema, etc?

1 Answer 1

17

I was able to use pg_restore to solve the problem:

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d my_db db/latest.dump 
Sign up to request clarification or add additional context in comments.

4 Comments

BTW, if you were on a current PostgreSQL version, psql would've told you that you were trying to restore a custom-format dump and should use pg_restore.
@CraigRinger where would it have said that? I'm using 9.4 and didn't see it.
@tyler Ah, might only do it for psql -f dumpfile. I think the patch made it into 9.4...

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.