我正在使用此命令在本地创建转储PGPASSWORD=admin pg_dump -h 127.0.0.1 -p 5432 -U postgres --no-owner --no-acl -f database.dump
和 my 已成功创建。
然后将此转储上传到 dropbox 并使用此链接公开 http://www.dropbox.com/s/rsqeiuqzusejz5x/database.dump?dl=1
通知我已将 https
更改为 http
,将 dl=0
更改为 dl=1
(dl=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.
我已经尝试了所有官方文档和各种答案,但似乎没有任何效果。
最佳答案
在进行进一步研究时,我发现 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
的情况不同。
有关更多详细信息,请参阅文档 here
关于python - 无法在heroku上恢复postgres转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61151338/