postgres=# \list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges --------------+----------+-----------+---------+-------+----------------------- test1 | postgres | UTF8 | C | C | test2 | postgres | sql_ASCII | C | C | test3 | postgres | sql_ASCII | C | C | test4 | postgres | sql_ASCII | C | C | template0 | postgres | sql_ASCII | C | C | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | sql_ASCII | C | C | postgres=CTc/postgres+ | | | | | =c/postgres (6 rows)
我需要一种方法来创建一个转储文件,其中包含我正在尝试转储的数据库的模式 – 包括CREATE DATABASE语句.
到目前为止,我已经发现:
pg_dump -s -U postgres -d test1 > test1_only.sql
将仅为test1数据库创建模式,但它不包括CREATE DATABASE命令.
我能够获得CREATE DATABASE命令的唯一方法是:
pg_dumpall -s -U postgres > /schema_alldatabases.sql
将转储所有数据库的架构.但是,这当然包括所有数据库的所有模式.在我要恢复此文件的服务器上,我已经有test3和test4 ……我不想覆盖它们,因为模式不同.
无论如何让pg_dump -s命令包含CREATE DATABASE命令?
或者,我应该只使用pg_dumpall并控制我恢复的内容?如果是这样,你能告诉我如何从转储文件中恢复test1吗?
谢谢.
pg_dump --create -s -U postgres -d test1 > test1_only.sql
Begin the output with a command to create the database itself and reconnect to the created database. (With a script of this form,it doesn’t matter which database in the destination installation you connect to before running the script.) If –clean is also specified,the script drops and recreates the target database before reconnecting to it.
http://www.postgresql.org/docs/current/static/app-pgdump.html
原文地址:https://www.jb51.cc/postgresql/192181.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。