是否有办法使pg_dump排除特定序列?

问题描述 投票:17回答:2

我想从我的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 documentation中所述与pg_restore结合使用tar格式的数据库对象来启用/禁用它,但我不会使用pg_restore。

非常感谢

格雷厄姆

postgresql sequences pg-dump
2个回答
27
投票

有两种情况:

  1. 要排除的顺序是归表所有,您也在转储(典型情况:SERIAL列)。请参阅:Dump a table without sequence table in postgres简短的回答:不,序列不能搁置。

  2. 序列由转储表不拥有。然后可以使用--exclude-table开关将其排除,就好像它是一个表一样。

来自pg_dump文档:

-T表--exclude-table = table

Do not dump any tables matching the table pattern.

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

关于-t

-t表--table = table

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

0
投票

如果序列归表所有,则可以使用-T排除序列和表,例如:

pg_dump -T table -T table_id_seq
© www.soinside.com 2019 - 2024. All rights reserved.