无法恢复 Heroku 上的 Postgres 转储

ama*_*yal 4 python django postgresql heroku django-rest-framework

我正在使用此命令在本地创建转储 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 = 1以使其可下载)dl=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.
Run Code Online (Sandbox Code Playgroud)

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

ama*_*yal 5

在进行进一步研究时,我发现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不使用时的情况不同。

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