【问题标题】:How to restore db dump using psycopg2如何使用 psycopg2 恢复数据库转储
【发布时间】:2019-06-12 16:48:09
【问题描述】:

我正在使用 linux 命令行的 pg_dump 命令备份 postgres 数据库。 想要使用 psycopg2 恢复数据库。运行以下命令

cur.execute(open("db.sql", "r").read())

抛出错误:

syntax error at or near "\"
LINE 1890: \.

【问题讨论】:

  • sql文件第1890行的内容是什么?也许这是 psql 反斜杠命令,psycopg2 不支持?

标签: python-3.x ubuntu-14.04 psycopg2 psql


【解决方案1】:

如果你在命令行中进行转储,为什么不再次使用它来恢复?

在命令行中: psql dbname

如果您需要在 python 脚本中执行此操作,您可以使用“子进程”并触发相同的命令。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2021-06-05
    • 2022-01-04
    • 2023-01-02
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    相关资源
    最近更新 更多