有没有办法让pg_dump排除特定的序列?

22

我想在将输出放入纯文本文件的 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_dump文档中所述的那样,在tar格式中组合启用/禁用数据库对象,但是我不会使用pg_restore。

非常感谢。

Graham

2个回答

32
有两种情况:
  1. 要排除的序列属于你正在导出的表(典型情况:SERIAL列)。
    参考:Dump a table without sequence table in postgres
    简短回答:不行,不能排除序列。

  2. 序列不属于要导出的表。那么可以使用--exclude-table开关来排除它,就像排除表一样。

来自pg_dump文档:

-T table --exclude-table=table

Do not dump any tables matching the table pattern.

The pattern is interpreted according to the same rules as for -t

关于-t

-t table
--table=table

Dump only tables (or views or sequences or foreign tables) matching table

这是一个不属于表的序列,因此排除表选项非常有效。 - Graham
1
“-T table”语句非常重要。不要让你的直觉在这一部分上欺骗你。按照CLI参数的标准,你可能会认为“-T table”已经在“--exclude-table=table”中声明,因此不再需要它。看起来似乎是参数冗余,但实际上它对于成功排除非常必要。 - Abel Callejo

2
如果序列由一个表所拥有,您可以使用 -T 参数来同时排除序列和表,例如:
```-T table_name.sequence_name```
pg_dump -T table -T table_id_seq

这不会将序列和表都从转储中排除吗? - Ihor Pomaranskyy
@IgorPomaranskiy 是的 - AlexDev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接