我正在尝试使用pg_dump
/pg_restore
utils将本地PostgreSQL数据库复制到Heroku应用程序。根据Heroku的官方指南:https://devcenter.heroku.com/articles/heroku-postgres-import-export
所以,我已经完成了转储:pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
然后我把它上传到了一个可以通过web服务器访问的文件上(它真的可以访问,我检查过它用wget
和pg_restore
下载文件,效果很好)。
然后我试图在Heroku上恢复,但没有运气:
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.
以下是详细信息:
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
我试着重新制作转储文件,重新加载它——同样的错误。怎么了?为什么我可以在刚刚创建的DB上下载它并从中恢复,而不能在Heroku上?
谢谢你的建议。
我未能以上述方式加载转储,但我找到了另一个对我来说很好的解决方案:
以简单的SQL格式进行转储:pg_dump --no-owner mydb > mydb.dump
您可能需要切换到有权访问您的数据库的用户,例如postgres
。所以,sudo su postgres
,然后进行转储。
然后用psql
工具加载:user@pc:~/path/to/your/dump$ heroku pg:psql < mydb.dump
文件的管道似乎有问题。我使用-f命令创建了转储来指定文件,这解决了我的问题。
pg_dump -f mydb.dump -Fc --no-acl -no-owner -h localhost -U myUser --schema=public myDatabase
刚刚遇到这个问题,我无法使用这里提供的答案,但由于某种原因,将输出文件的扩展名更改为.psql
成功地解决了这个问题。
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.psql