python - 无法在heroku上恢复postgres转储

标签 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 和 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/

相关文章:

python - 为什么在卷积神经网络中可能有低损失,但准确率也很低?

python - 在python中的字符串列表中用数字分隔值

python - Pandas 数据帧 : averaging values in one col because another col has duplicates

python - Firebase python admin sdk isNewUser ()

java - Hibernate 与 postgres 发生异常,无法找到表

python - regEx 在 notepad++ 中有效,但在 python 中无效

django - 一次性 Django 脚本的已弃用 setup_environ() 的替代方案?

python - Django url 测试用例

PostgreSQL 错误 : EXECUTE of SELECT . .. INTO 未实现

java - Postgres 9.2 - 恢复转储正在翻译转义的 unicode 并破坏 java 序列化对象