2016-03-26 89 views
2

我想將我的本地PostgreSQL數據庫複製到Heroku應用程序pg_dump/pg_restore utils。根據Heroku的官方指南做:https://devcenter.heroku.com/articles/heroku-postgres-import-export在Heroku上不能讀pg_restore:「無法從輸入文件讀取:文件結尾」

所以,我已經做了轉儲:
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump

然後我上傳它可達整個網絡服務器(和它的真正到達,我檢查它下載與wgetpg_restore文件 - 工作正常)。

然後我試圖恢復在Heroku和沒有運氣:

[email protected]:~/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. 

下面是詳細信息:

[email protected]:~/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 

我試圖重塑轉儲文件,重新加載它 - 同樣的錯誤。怎麼了?爲什麼我可以在剛創建的數據庫上下載並從中恢復,但不能在Heroku上進行恢復?

謝謝你的任何建議。

+0

這種解決方案可能是相關的一些人:http://stackoverflow.com/questions/42433414/heroku-database-restore-issue/42435490#42435490 –

回答

3

我無法加載轉儲上述方法準確描述,但我已經來到另一個解決方案,它爲我工作得很好:

在做簡單的SQL格式轉儲:
pg_dump --no-owner mydb > mydb.dump

您可能需要切換到有權訪問您的數據庫的用戶,例如postgres。所以,sudo su postgres然後進行轉儲。

然後用psql工具加載:
[email protected]:~/path/to/your/dump$ heroku pg:psql < mydb.dump