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吗?
谢谢.
使用–create或-C选项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
总结以上是内存溢出为你收集整理的postgresql – 如何让pg_dump -s包含CREATE DATABASE命令?全部内容,希望文章能够帮你解决postgresql – 如何让pg_dump -s包含CREATE DATABASE命令?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)