Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

postgresql - 为特定的表和条目创建数据库转储(Creating a database dump for specific tables and entries Postgres)

I have a database with hundreds of tables, what I need to do is export specified tables and insert statements for the data to one sql file.

(我有一个包含数百个表的数据库,我需要做的是导出指定的表,并将数据的插入语句插入一个sql文件。)

The only statement I know can achieve this is

(我知道的唯一可以实现这一目标的语句是)

pg_dump -D -a -t zones_seq interway > /tmp/zones_seq.sql

Should I run this statement for each and every table or is there a way to run a similar statement to export all selected tables into one big sql big.

(我应该为每个表运行此语句,还是有一种方法可以运行类似的语句将所有选定的表导出到一个大sql big中。)

The pg_dump above does not export the table schema only inserts, I need both

(上面的pg_dump不会导出仅插入的表模式,我需要两个)

Any help will be appreciated.

(任何帮助将不胜感激。)

  ask by Roland translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Right from the manual : " Multiple tables can be selected by writing multiple -t switches "

(直接来自手册 :“ 可以通过编写多个-t开关来选择多个表 ”)

So you need to list all of your tables

(因此,您需要列出所有表格)

pg_dump --column-inserts -a -t zones_seq -t interway -t table_3 ... > /tmp/zones_seq.sql  

Note that if you have several table with the same prefix (or suffix) you can also use wildcards to select them with the -t parameter:

(请注意,如果您有多个具有相同前缀(或后缀)的表,则还可以使用通配符通过-t参数选择它们:)

" Also, the table parameter is interpreted as a pattern according to the same rules used by psql's \d commands "

(“ 而且,根据psql的\ d命令使用的相同规则,将表参数解释为模式 ”)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...