【问题标题】:Can I run a pg_dump automatically removing reference to the owner?我可以运行 pg_dump 自动删除对所有者的引用吗?
【发布时间】:2017-03-20 23:27:24
【问题描述】:

我希望能够有效地将我们的 postgre 生产数据库的内容克隆到无主的本地数据库。我已经成功地做到了,但这是一个费力的过程,需要以下步骤

$ pg_dump [prod_db] > tempfile

[Go through tempfile manually removing all 60ish references to the owner, named 'postgres']

$ cat tempfile > psql [local_db]

否则,当我运行最后一步时,我收到一堆 SQL 错误消息,上面写着ERROR: role "postgres" does not exist。我尝试使用匹配的'postgres'所有者重新创建本地数据库,但是a)我仍然遇到相同类型的错误,并且b)我不想为我的本地数据库设置所有者,如果这意味着我将拥有登录。

如果我以后想重新克隆它,是否有最佳实践/有效的方法?

【问题讨论】:

    标签: bash postgresql pg-dump database-cloning


    【解决方案1】:

    使用 -O 开关不在转储中定义所有者。

    【讨论】:

      【解决方案2】:

      没有所有者集是不正常的 Postgres 设计。为了避免必须登录到您的 postgres 数据库,您可以设置一个 .pgpass 文件。这是一个纯文本文件,应设置为 600 权限。内容将如下所示:

      hostname:port:database:username:password
      

      每个连接可以在一条线上。

      此外,对于本地数据库连接,假设您已正确设置其余安全性(ssh 证书等),您可以编辑 pg_hba.conf 文件并将本地连接身份验证方法设置为“信任”。这显然不建议用于生产或敏感数据。该行将如下所示:

      local   all             all                                     trust
      

      默认方法是“对等”。除非您在 .pgpass 文件中设置您的用户名,否则您仍然需要与 psql -U postgres 连接,但您不需要输入密码。

      【讨论】:

        猜你喜欢
        • 2013-12-19
        • 2011-12-11
        • 2023-02-01
        • 2023-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        相关资源
        最近更新 更多