在 pg_restore 期间排除 Table
Exclude Table during pg_restore
更新:
能够在 pg_dump 命令期间排除 table 中的数据。比尝试不加载数据更快,因为您不必等待数据被转储。
--exclude-table-data=event_logs
(PostgreSQL) 9.4.4
有人知道如何在执行 pg_restore
时排除 table 吗?我可以在做 pg_dump
时找到如何做。但是我不是做转储的人,也不能排除它们。
转储中有 2 个 table 非常大,在我进行恢复时会占用很长时间,所以我想跳过它们。
pg_restore 没有排除 table 参数,它有一个包含 table 参数。
-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.
如果您有大量 table,则需要进行一些输入,但它确实允许您排除特定的 table,只需将他们的名字留在列表。
我遇到了同样的问题。一个很长的 table 列表,我想从一些 table 中排除数据。
我所做的是:
运行
pg_restore -l $pgdump_file > restore.pgdump.list
在编辑器中打开 restore.pgdump.list
文件,并在
行前面插入一个 ;
;2429; 0 27550 TABLE DATA public <table_to_explore> <database>
保存该文件后,它现在可以用于导入,其中所有以 ;
开头的行都将被忽略。
pg_restore -L restore.pgdump.list | psql
如果您完全想忽略特定的 table.[=18,则可以在具有特定 table 名称的行前面添加一行 ;
=]
man pg_restore
也在文档末尾的示例中讲述了这一点。
此处命令无效:
pg_restore -L restore.pgdump.list | psql
Jesper Grann Laursen 已回答!
这里它按照以下顺序工作:
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
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
以下return是恢复的“待办事项列表”:
pg_restore -l /path/to/db/dump
以下将 return 除 table_to_ignore
之外的所有内容(grep
选项 -v
使其反转匹配):
pg_restore -l /path/to/db/dump | grep -v 'TABLE DATA public table_to_ignore'
这可以与需要输入待办事项列表的 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
如果要忽略多个表,可以 grep 到:
pg_restore -l /path/to/db/dump | grep -vE 'TABLE DATA public (table_1|table_2|table_3)'
请注意 grep
的 -E
选项的存在,以使用扩展的正则表达式。
更新: 能够在 pg_dump 命令期间排除 table 中的数据。比尝试不加载数据更快,因为您不必等待数据被转储。
--exclude-table-data=event_logs
(PostgreSQL) 9.4.4
有人知道如何在执行 pg_restore
时排除 table 吗?我可以在做 pg_dump
时找到如何做。但是我不是做转储的人,也不能排除它们。
转储中有 2 个 table 非常大,在我进行恢复时会占用很长时间,所以我想跳过它们。
pg_restore 没有排除 table 参数,它有一个包含 table 参数。
-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.
如果您有大量 table,则需要进行一些输入,但它确实允许您排除特定的 table,只需将他们的名字留在列表。
我遇到了同样的问题。一个很长的 table 列表,我想从一些 table 中排除数据。
我所做的是:
运行
pg_restore -l $pgdump_file > restore.pgdump.list
在编辑器中打开 restore.pgdump.list
文件,并在
;
;2429; 0 27550 TABLE DATA public <table_to_explore> <database>
保存该文件后,它现在可以用于导入,其中所有以 ;
开头的行都将被忽略。
pg_restore -L restore.pgdump.list | psql
如果您完全想忽略特定的 table.[=18,则可以在具有特定 table 名称的行前面添加一行 ;
=]
man pg_restore
也在文档末尾的示例中讲述了这一点。
此处命令无效:
pg_restore -L restore.pgdump.list | psql
Jesper Grann Laursen 已回答!
这里它按照以下顺序工作:
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
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
以下return是恢复的“待办事项列表”:
pg_restore -l /path/to/db/dump
以下将 return 除 table_to_ignore
之外的所有内容(grep
选项 -v
使其反转匹配):
pg_restore -l /path/to/db/dump | grep -v 'TABLE DATA public table_to_ignore'
这可以与需要输入待办事项列表的 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
如果要忽略多个表,可以 grep 到:
pg_restore -l /path/to/db/dump | grep -vE 'TABLE DATA public (table_1|table_2|table_3)'
请注意 grep
的 -E
选项的存在,以使用扩展的正则表达式。