postgresql 有没有办法让 pg_dump 排除特定序列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20216673/
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
Is there a way to get pg_dump to exclude a specific sequence?
提问by Graham
I want to exclude a sequence from my pg_dump command which is putting the output into a plain file.
我想从我的 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
I know there are switches for tables which i am using above and that you can enable/disable database objects in the tar format in combination with pg_restore as stated in the pg_dump documentationbut I will not be using pg_restore.
我知道有我在上面使用的表的开关,你可以启用/禁用 tar 格式的数据库对象,结合pg_dump 文档中所述的 pg_restore,但我不会使用 pg_restore。
Many Thanks
非常感谢
Graham
格雷厄姆
回答by Daniel Vérité
There are two cases:
有两种情况:
The sequence to exclude is owned by a tableyou're also dumping (typical case:
SERIAL
column).
See: Dump a table without sequence table in postgres
Short answer: no, the sequence can't be left aside.The sequence is not ownedby a dumped table. Then it can be excluded with the
--exclude-table
switch as if it was a table.
要排除的序列由您也转储的表拥有(典型情况:
SERIAL
列)。
请参阅:在 postgres 中转储没有序列表的表
简短回答:不,序列不能放在一边。该序列不属于转储表。然后它可以用
--exclude-table
开关排除,就好像它是一张桌子一样。
From pg_dump documentation:
从 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 表 --exclude-table=table
Do not dump any tables matching the table pattern.
该模式根据与 -t 相同的规则进行解释
And about -t
:
而关于-t
:
-t table
--table=tableDump only tables (or views or sequences or foreign tables) matching table
-t 表
--table=tableDump only tables (or views or sequences or foreign tables) matching table
回答by AlexDev
If the sequence is owned by a table you can exclude both the sequence and the table using -T, such as:
如果序列归表所有,您可以使用 -T 排除序列和表,例如:
pg_dump -T table -T table_id_seq