【问题标题】:Create a copy of db schema only psql仅创建 db 模式的副本 psql
【发布时间】:2016-05-18 17:23:34
【问题描述】:

我有一个名为“mydb”的数据库。现在我怎样才能创建一个名为“mydb_test”的新数据库,只有“mydb”的架构

试过以下链接PostgreSQL how to create a copy of a database or schema?

如上所述,我尝试了以下命令,

createdb -T olddb newdb

这会将包括数据在内的数据复制到newdb中

如果我尝试上面链接中提到的第二个选项,我会收到以下错误,

# pg_dump -Cs -U postgres my_test_db > dump_schema_file
# psql -U postgres naggappan_my_test_db < dump_schema_file
 psql: FATAL:  database "naggappan_my_test_db" does not exist

我怎样才能只接受架构

【问题讨论】:

    标签: psql


    【解决方案1】:
    • 您可以创建一个没有所需架构数据的新转储,然后从中恢复到新数据库:

      # pg_dump --dbname=source_db_name --username=postgres --encoding=UTF8 --schema=db_schema --schema-only --file=path_to_filename.dump

      # psql --dbname=target_db_name --username=postgres --file=path_to_filename.dump

    • 如果您有一个包含 binary 格式的架构和/或数据的现有转储,您可以使用 pg_restore 仅从中恢复架构:

      # pg_restore --dbname=target_db_name --username=postgres --schema-only path_to_filename.dump

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      相关资源
      最近更新 更多