为特定的表和条目创建数据库转储 [英] Creating a database dump for specific tables and entries Postgres

查看:76
本文介绍了为特定的表和条目创建数据库转储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

The only statement I know can achieve this is

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

我应该为每个表运行此语句还是有办法运行类似的语句将所有选定的表导出到一个大sql big中。上面的pg_dump不会导出仅插入表模式的数据,我同时需要

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. The pg_dump above does not export the table schema only inserts, I need both

任何帮助将不胜感激。

推荐答案

手册可以通过编写多个-t开关选择多个表

因此您需要列出所有表

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

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

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:

参数根据psql的\d命令使用的相同规则解释为模式

这篇关于为特定的表和条目创建数据库转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆