postgresql 在 pg_restore 期间排除表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37038193/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:15:58  来源:igfitidea点击:

Exclude Table during pg_restore

postgresqlpg-restore

提问by covard

UPDATE:Was able to exclude the data in the table durning the pg_dump command. Makes it even faster than trying to not load the data because you don't have to wait for that data to be dumped.

更新:能够在 pg_dump 命令期间排除表中的数据。比尝试不加载数据更快,因为您不必等待数据被转储。

--exclude-table-data=event_logs

--exclude-table-data=event_logs

(PostgreSQL) 9.4.4

(PostgreSQL) 9.4.4

Anyone know how to exclude a table when doing a pg_restore? I can find how to do it when doing a pg_dump. However I am not the one doing the dump and can't exclude them.

任何人都知道如何在执行时排除表格pg_restore?我可以在执行pg_dump. 但是,我不是做转储的人,也不能排除它们。

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 个表,它们非常大,并且在我进行恢复时需要花费很长时间,所以我想跳过它们。

采纳答案by e4c5

pg_restoredoes not have an exclude table parameter, what it does have is an include table parameter.

pg_restore没有排除表参数,它有一个包含表参数。

-t table

--table=table

Restore definition and/or data of named table only. Multiple tables may be specified with multiple -t switches. This can be combined with the -n option to specify a schema.

-t 表

--table=table

仅恢复命名表的定义和/或数据。可以使用多个 -t 开关指定多个表。这可以与 -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.

如果您有大量表格,它确实需要一点点输入,但它确实允许您通过将特定表格的名称排除在列表之外来排除它们。

回答by Jesper Grann Laursen

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.listfile in an editor, and insert an ;in front of the line saying

restore.pgdump.list在编辑器中打开该文件,并;在该行前面插入一个说

;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_restoreis also telling about this in an example in the end of the documentation.

man pg_restore还在文档末尾的示例中讲述了这一点。

回答by Fred William Torno Junior

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

回答by user3132194

Here is one-liner, based on other answers:

这是基于其他答案的单行:

pg_restore -L <(pg_restore -l ~/base.bck | grep -ivE 'TABLE DATA public (exclude_tbl_name|exclude_tbl_name_2|exclude_tbl_name_3)') -d base_truncated ~/base.bck