【问题标题】:How to restore pg_dump file into postgres database如何将 pg_dump 文件恢复到 postgres 数据库
【发布时间】:2018-07-22 15:18:15
【问题描述】:

所以我定期使用 pgadmin4 备份和恢复数据库和架构。我想使用 pg_dump 和 pg_restore 等命令来处理批处理文件。然而,我总是无法在这方面取得成功,并且可以使用一些帮助。我尝试转储一个模式(带有数据)的方式如下:

pg_dump -U postgres -F c -d database -n schema > mw2

然后我尝试使用 pg_restore 恢复它:

pg_restore -U postgres -d otherdatabase -n schema mw2

首先我尝试使用 .dump 代替 tar 但结果保持不变;这是我数据库中的一个空架构。

或以下错误信息:

pg_restore: [archiver] input file does not appear to be a valid archive

【问题讨论】:

    标签: postgresql pg-dump pg-restore


    【解决方案1】:

    https://www.postgresql.org/docs/current/static/app-pgrestore.html

    --format=format 指定存档的格式。不需要指定格式,因为 pg_restore 将确定格式 自动地。如果指定,它可以是以下之一:

    自定义、目录和tar

    https://www.postgresql.org/docs/current/static/app-pgdump.html

    --format=格式

    选择输出格式。格式可以是以下之一:

    p plain 输出纯文本 SQL 脚本文件(默认)。

    其他是自定义、目录和tar

    简而言之 - 您使用了默认的 plain 格式,它适用于 psql,而不是 pg_restore。因此,要么使用pg_dump 指定不同的格式,要么使用您的文件作为

    psql -f  mw2.tar
    

    【讨论】:

    • 现在通过在转储中添加 -F t 来尝试一下
    • 现在执行;但生成的架构保持为空。还是不行;生病更新我的代码
    • 现在查看 psql -f mw2.tar,但我首先需要在那里选择正确的数据库和架构。
    • 请不要乱发帖子。如果你现在有不同的问题 - 尝试在现有帖子之间找到解决方案,你没有 - 问一个新问题
    • @Zuenie 是的——当然,就像psql -U postgres -d otherdatabase -f mw2。我只提到了-f 键,因为它是不同的
    猜你喜欢
    • 1970-01-01
    • 2023-01-03
    • 2021-05-07
    • 2018-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    相关资源
    最近更新 更多