Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant pg_restore on Heroku: "could not read from input file: end of file"

I am trying to copy my local PostgreSQL DB to Heroku app with pg_dump / pg_restore utils. Doing according to Heroku's official guide: https://devcenter.heroku.com/articles/heroku-postgres-import-export

So, i've done the dump:
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump

Then i've uploaded it on a reachable across the web server (and its really reachable, i've checked it downloading the file with wget and pg_restoreing it - works fine).

Then i've tried to restore in on Heroku and no luck:

kulver@kvb:~/projects/gop/gop_flask$ heroku pg:backups restore 'MY_URL_HERE' postgresql-corrugated-15763
r010 ---restore---> DATABASE
An error occurred and your backup did not finish.

Please run `heroku pg:backups info r010` for details.

Here are the details:

kulver@kvb:~/projects/gop/gop_flask$ heroku pg:backups info r010
=== Backup info: r010

Database:    BACKUP
Started:     2016-03-26 20:15:32 +0000
Finished:    2016-03-26 20:15:32 +0000
Status:      Failed
Type:        Manual
Backup Size: 23.9MB
=== Backup Logs
... a bunch of logs here ...
2016-03-26 20:15:32 +0000: pg_restore: processing data for table "cards"
2016-03-26 20:15:32 +0000: waiting for restore to complete
2016-03-26 20:15:32 +0000: pg_restore: [custom archiver] could not read from input file: end of file
2016-03-26 20:15:32 +0000: restore done
2016-03-26 20:15:32 +0000: waiting for download to complete
2016-03-26 20:15:32 +0000: download done

I've tried to remake the dump file, reload it - same error. What's wrong? Why can i download it and restore from it on the just created DB, but not on Heroku?

Thank you for any advise.

like image 290
Mikhail Savushkin Avatar asked Mar 26 '16 20:03

Mikhail Savushkin


2 Answers

There appears to be an issue with piping to the file. I created the dump using the -f command to specify the file and that solved my issue.

pg_dump -f mydb.dump -Fc --no-acl -no-owner -h localhost -U myUser --schema=public myDatabase 
like image 147
Scott Morrison Avatar answered Oct 22 '22 16:10

Scott Morrison


I failed to load the dump in the exact described above way, BUT i've come to another solution which worked fine for me:

Make the dump in simple SQL format:
pg_dump --no-owner mydb > mydb.dump

You may need to switch to the user who has rights to access your DB, postgres for example. So, sudo su postgres and then make the dump.

And then load it with psql tool:
user@pc:~/path/to/your/dump$ heroku pg:psql < mydb.dump

like image 45
Mikhail Savushkin Avatar answered Oct 22 '22 15:10

Mikhail Savushkin