[英]Exclude Table during pg_restore
UPDATE: Was able to exclude the data in the table durning the pg_dump command.更新:能够在 pg_dump 命令期间排除表中的数据。 Makes it even faster than trying to not load the data because you don't have to wait for that data to be dumped.
比尝试不加载数据更快,因为您不必等待数据被转储。
--exclude-table-data=event_logs
(PostgreSQL) 9.4.4
Anyone know how to exclude a table when doing a pg_restore
?有人知道如何在执行
pg_restore
时排除表吗? I can find how to do it when doing a pg_dump
.我可以在执行
pg_dump
时找到如何做到这一点。 However I am not the one doing the dump and can't exclude them.但是,我不是进行转储的人,也不能排除它们。
There are 2 tables in the dump that are really big and take forever when I do a restore so I want to skip them.转储中有 2 个表,它们非常大,并且在我进行恢复时需要花费很长时间,所以我想跳过它们。
I had the same problem.我有同样的问题。 A long table list, and I want exclude the data from a few of the tables.
一个长表列表,我想从几个表中排除数据。
What I did was the following:我所做的是以下内容:
Run运行
pg_restore -l $pgdump_file > restore.pgdump.list
Open that restore.pgdump.list
file in an editor, and insert an ;
在编辑器中打开该
restore.pgdump.list
文件,并插入一个;
in front of the line saying在行前说
;2429; 0 27550 TABLE DATA public <table_to_explore> <database>
After saving the that file, it can now be used for importing, where all lines starting with ;
保存该文件后,它现在可以用于导入,其中所有行都以
;
开头;
are ignored.被忽略。
pg_restore -L restore.pgdump.list | psql
You could make an one-liner to add ;
你可以做一个单行添加
;
in front of lines having a specific table name, if you completely want to ignore a specific table.在具有特定表名的行之前,如果您完全想忽略特定表。
man pg_restore
is also telling about this in an example in the end of the documentation. man pg_restore
也在文档末尾的示例中讲述了这一点。
TL;DR One-liner TL;DR 单线
pg_restore -L <(pg_restore -l /path/to/db/dump | grep -v 'TABLE DATA public table_to_ignore') -d db_name_where_to_restore /path/to/db/dump
The following returns the "todo list" for a restore:以下返回还原的“待办事项列表”:
pg_restore -l /path/to/db/dump
The following will return all except table_to_ignore
( grep
option -v
makes it inverse the match):以下将返回除
table_to_ignore
之外的所有table_to_ignore
( grep
选项-v
使其反向匹配):
pg_restore -l /path/to/db/dump | grep -v 'TABLE DATA public table_to_ignore'
This can be used in combination with pg_restore
option -L
which expects a input todo list:这可以与
pg_restore
选项-L
结合使用,该选项需要输入待办事项列表:
pg_restore -L <(pg_restore -l /path/to/db/dump | grep -v 'TABLE DATA public table_to_ignore') -d db_name_where_to_restore /path/to/db/dump
If you have several tables to ignore, you can the grep to:如果你有几个表要忽略,你可以 grep 到:
pg_restore -l /path/to/db/dump | grep -vE 'TABLE DATA public (table_1|table_2|table_3)'
Notice the presence of -E
option for grep
to use an extended regular expression.请注意
-E
选项的存在,用于grep
使用扩展的正则表达式。
pg_restore does not have an exclude table parameter, what it does have is an include table parameter.pg_restore没有排除表参数,它有一个包含表参数。
-t table
-t 表
--table=table
--table=table
Restore definition and/or data of named table only.
仅恢复命名表的定义和/或数据。 Multiple tables may be specified with multiple -t switches.
可以使用多个 -t 开关指定多个表。 This can be combined with the -n option to specify a schema.
这可以与 -n 选项结合使用来指定模式。
If you have a large number of tables it does call for a litte bit of typing, but it does allow you to exclude specific tables by just leaving their names out of the list.如果您有大量表格,它确实需要一点点输入,但它确实允许您通过将特定表格的名称排除在列表之外来排除它们。
here the command did not work:这里命令不起作用:
pg_restore -L restore.pgdump.list | psql
answered by Jesper Grann Laursen!由 Jesper Grann Laursen 回答!
Here it worked by following the following sequence:这里它按照以下顺序工作:
pg_restore -l $pgdump_file > restore.pgdump.list
;2429; 0 27550 TABLE DATA public <table_to_explore> <database>
pg_restore -v -L restore.pgdump.list -d dbname pgdump.file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.