【问题标题】:clone postgres database with new name使用新名称克隆 postgres 数据库
【发布时间】:2018-05-09 07:23:53
【问题描述】:

我在157.157.35.333 上有一个users-production 数据库

我想将它克隆到另一台主机上users-sandbox

这是我尝试过的:

    PRODUCTION_HOST=111.111.11.111
    SANDBOX_HOST=222.222.22.222

    echo "creating db on sanbox"
    psql -h ${SANDBOX_HOST} -U postgres  -c "CREATE DATABASE \"users-sandbox\";"

    pg_dump -h ${PRODUCTION_HOST} -U postgres  -d users-production -F c -b -v  | \
       pg_restore -C -c -h ${SANDBOX_HOST} -U postgres  -d users-sandbox -v

但这会使用旧名称创建数据库

如何使用新名称创建?

【问题讨论】:

  • 不幸的是它没有..

标签: postgresql pg-restore


【解决方案1】:

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

-d 数据库名

连接到数据库 dbname 并直接恢复到数据库中。

但是!

-C

--创建

在还原到数据库之前创建数据库。如果 --clean 也是 在连接到之前指定、删除并重新创建目标数据库 它。

使用此选项时,以 -d 命名的 数据库仅用于 发出初始的 DROP DATABASE 和 CREATE DATABASE 命令。所有数据 恢复为存档中出现的数据库名称

所以从pg_restore 参数中删除-C...

(我的引号格式)

【讨论】:

    猜你喜欢
    • 2019-03-04
    • 1970-01-01
    • 2016-04-06
    • 2011-06-23
    • 2011-07-29
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多