首页 > 解决方案 > 无法在heroku上恢复postgres转储

问题描述

我正在使用此命令在本地创建转储, PGPASSWORD=admin pg_dump -h 127.0.0.1 -p 5432 -U postgres --no-owner --no-acl -f database.dump并且我的已成功创建。

然后将此转储上传到保管箱并通过此链接http://www.dropbox.com/s/rsqeiuqzusejz5x/database.dump?dl=1通知将其公开我已更改httpshttp和(dl = 1dl=0dl=1 使其可下载)

然后在我的终端上我正在运行这个命令heroku pg:backups:restore "http://www.dropbox.com/s/38prh2y7pdwhqqj/database.dump?dl=1" --confirm tranquil-anchorage-39635

但我收到了这个错误

 !    An error occurred and the backup did not finish.
 !
 !    pg_restore: error: did not find magic string in file header
 !    waiting for restore to complete
 !    pg_restore finished with errors
 !    waiting for download to complete
 !    download finished successfully
 !
 !    Run heroku pg:backups:info r010 for more details.

我已经尝试了所有官方文档和各种答案,但似乎没有任何效果。

标签: pythondjangopostgresqlherokudjango-rest-framework

解决方案


在进行进一步研究时,我发现pg_restore在恢复转储文件时该命令需要在创建转储文件时必须提及的某种格式。这就是出现错误的原因 pg_restore: error: did not find magic string in file header

pg_dump -h <localhost> -p <port> -U <username> --format=c <database_name> > daman.dump 运行此命令后,您将被提示输入用户密码。

注意--format=c上面的命令。这将创建一个可以通过 恢复的格式的转储文件pg_restore,我还应该提到,以这种方式创建的转储文件对于记事本或 vscode 等文本编辑器不可读,这与--format=c不使用的情况不同。

有关更多详细信息,请参阅此处的文档


推荐阅读