如何备份一些有数据的表和一些表只有模式 PostgreSQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6860167/
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 to backup some tables with data and some tables only schema PostgreSQL
提问by Diego Faria
I want to dump a database.
我想转储一个数据库。
I have three tables:
我有三个表:
table1 table2 table3
表1 表2 表3
From table1 i want the schema plus data.
从 table1 我想要模式加上数据。
From table2 and table3 i just want the schema.
从 table2 和 table3 我只想要模式。
How do i do that?
我怎么做?
回答by Diego Faria
To get data from just a few tables:
要从几个表中获取数据:
pg_dump myDatabase --inserts -a -t table1 -t table2 > backup.sql;
pg_dump myDatabase --inserts -a -t seq1 -t seq2 > backupSequences.sql;
Parameters descriptions:
-a, --data-only dump only the data, not the schema
-t, --table=TABLE dump the named table(s) only
--inserts dump data as INSERT commands, rather than COPY
pg_dump myDatabase --inserts -a -t table1 -t table2 > backup.sql;
pg_dump myDatabase --inserts -a -t seq1 -t seq2 > backupSequences.sql;
参数说明:
-a, --data-only 只转储数据,不转储模式
-t, --table=TABLE 仅转储命名表
-- 将转储数据插入为 INSERT 命令,而不是 COPY
This is what i wanted :)
这就是我想要的:)
Thanks all!
谢谢大家!