21

我想从我的 pg_dump 命令中排除一个序列,该命令将输出放入一个普通文件中。

Command: /Library/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5433 --username xxx --format plain --clean --inserts --verbose --file /Users/xxx/documents/output/SYSTEM_admin_20131126015325.sql --exclude-table public.table1 --exclude-table public.table2 mydatabase

我知道我在上面使用的表有开关,并且您可以结合 pg_restore 启用/禁用 tar 格式的数据库对象,如pg_dump 文档中所述,但我不会使用 pg_restore。

非常感谢

格雷厄姆

4

2 回答 2

30

有两种情况:

  1. 要排除的序列您也转储的表拥有(典型情况:SERIAL列)。
    请参阅:在 postgres 中转储没有序列表的表
    简短回答:不,不能将序列放在一边。

  2. 该序列不属于转储表。然后可以用--exclude-table开关排除它,就好像它是一张桌子一样。

来自 pg_dump 文档:

-T 表--排除表=表

Do not dump any tables matching the table pattern.

该模式根据与 -t 相同的规则进行解释

关于-t

-t 表
--table=表

Dump only tables (or views or sequences or foreign tables) matching table
于 2013-11-26T13:41:24.930 回答
0

如果序列由表拥有,您可以使用 -T 排除序列和表,例如:

pg_dump -T table -T table_id_seq
于 2019-12-19T19:35:33.700 回答