【问题标题】:Is there a way to get pg_dump to exclude a specific sequence?有没有办法让 pg_dump 排除特定序列?
【发布时间】:2013-11-26 12:08:23
【问题描述】:

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


    【解决方案1】:

    有两种情况:

    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
    

    【讨论】:

    • 它是一个不属于表的序列,所以 exclude-table 选项效果很好。
    • -T table 声明非常重要。不要让你的直觉在这方面欺骗你。根据 CLI 参数标准,您会认为不再需要 -T table,因为它已经在 --exclude-table=table 中说明。这似乎是多余的参数,但它确实是成功排除所必需的。
    【解决方案2】:

    如果序列属于某个表,可以使用-T同时排除该序列和该表,如:

    pg_dump -T table -T table_id_seq
    

    【讨论】:

    • 不会从转储中排除序列和表吗?
    • @IgorPomaranskiy 是的
    猜你喜欢
    • 2011-01-09
    • 1970-01-01
    • 2019-01-26
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 2020-02-01
    • 2011-11-27
    相关资源
    最近更新 更多