如何在 PostgreSQL 中进行仅模式备份和还原?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12564777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I do a schema only backup and restore in PostgreSQL?
提问by Sumit Munot
How do I take a schema level backup in PostgreSQL database and restore on the another database? Is there any single command available for this? For example, can I pg_dump and restore in single line?
如何在 PostgreSQL 数据库中进行模式级备份并在另一个数据库上恢复?是否有任何可用的命令?例如,我可以单行 pg_dump 和恢复吗?
回答by solaimuruganv
pg_dump --schema=masters oldDB > masters1.sql
cat masters1.sql | psql newDB
or
或者
in single command you can do by this
在单个命令中,您可以这样做
pg_dump oldDB --schema masters | psql -h localhost newDB;
回答by Sumit Munot
Backup schema and restore it on system for postgresql as below:
备份模式并在系统上为 postgresql 恢复它,如下所示:
Dump schema for database
数据库的转储模式
pg_dump -s database_name > db.sql
Dump schema for specific table
特定表的转储模式
pg_dump -s database_name -t table_name > db.sql
Restore backed up schema using below command
使用以下命令恢复备份的架构
psql -d database_name -h localhost -U postgres < path/db.sql
回答by Frank Heikens
What's wrong with the documentation?
文档有什么问题?
Example from the manual:
手册中的示例:
To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:
$ pg_dump -n 'east*gsm' -n 'west*gsm' -N 'test' mydb > db.sql
转储名称以东或西开头并以 gsm 结尾的所有模式,不包括名称包含单词 test 的任何模式:
$ pg_dump -n 'east*gsm' -n 'west*gsm' -N ' test' mydb > db.sql
回答by Frédérick Baldo
-s
or --schema-only
to exclude data from dump
Documentation
-s
或--schema-only
从转储文档中排除数据