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

时间:2013-11-26 12:08:23

标签: postgresql sequences pg-dump

我想从我的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。 / p>

非常感谢

格雷厄姆

2 个答案:

答案 0 :(得分:26)

有两种情况:

  1. 要排除的序列由表拥有您还要转储(典型案例:SERIAL列)。
    见:Dump a table without sequence table in postgres
    简答:不,序列不能放在一边。

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

  3. 来自pg_dump文档:

      

    -T表   --exclude表=表

    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
    

答案 1 :(得分:0)

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

pg_dump -T table -T table_id_seq
相关问题