首页 > 解决方案 > 从 pg_dump 中排除序列

问题描述

我正在创建一个 postgres 数据库(10.1)的导出,其中一些表被排除在外。我按照Is there a way to get pg_dump to exclude a specific sequence?. 但是,仍包括排除表的序列。有没有办法确保他们被拒之门外?

为了隔离问题,我创建了一个小型示例数据库,其中包含一个名为includeand的exclude表,为每个表添加了一行,并使用此命令导出数据库:

pg_dump --host=localhost --no-owner --no-acl --verbose --schema=public --dbname=export_test --exclude-table=exclude --file=exclude_table_only.dump

转储不包括exclude表,但确实包括序列:

...
--
-- TOC entry 198 (class 1259 OID 3818320)
-- Name: exclude_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE exclude_id_seq
...

标签: postgresqlpg-dump

解决方案


您应该能够使用另一个 --exclude-table 显式排除序列:

--exclude-table=exclude_id_seq

最终应该是这样的:

$ pg_dump --host=localhost --no-owner --no-acl --verbose --schema=public --dbname=export_test --exclude-table=exclude --exclude-table=exclude_id_seq --file=exclude_table_only.dump

推荐阅读