从 pg_dump 中排除序列

Mat*_*pel 3 postgresql pg-dump

我正在创建一个 postgres 数据库 (10.1) 的导出,其中排除了一些表。我按照有没有办法让 pg_dump 排除特定序列中的说明进行操作?. 但是,排除表的序列仍然包括在内。有没有办法确保他们被拒之门外?

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

pg_dump --host=localhost --no-owner --no-acl --verbose --schema=public --dbname=export_test --exclude-table=exclude --file=exclude_table_only.dump
Run Code Online (Sandbox Code Playgroud)

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

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

CREATE SEQUENCE exclude_id_seq
...
Run Code Online (Sandbox Code Playgroud)

Mic*_*ers 6

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

--exclude-table=exclude_id_seq
Run Code Online (Sandbox Code Playgroud)

最终应该是这样的:

$ 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
Run Code Online (Sandbox Code Playgroud)


Isa*_*lip 5

对于排除表,

--exclude-table
Run Code Online (Sandbox Code Playgroud)

将工作。

对于排除序列,

--exclude-table-data 
Run Code Online (Sandbox Code Playgroud)

将需要。

Postgres 12上测试

我无法--exclude-table排除序列,即表数据。

转储排除序列的示例,

$ pg_dump -v -C -Fp -O -x -h employee.us-east-1.rds.amazonaws.com \ 
          -U user1 -d emp -n empschema \ 
          --exclude-table="empschema.employee_history_id_seq" \ 
          -f dump-test.sql

where,
-v : verbose
-C : create Database commands in dump
-Fp : output file in plain Text
-O : no owner details in dump
-x : no privileges details in dump
-h : hostname
-U : username
-d : database
-n : schema
--exclude-table-data : excluding the sequence
-f : file to be written into
Run Code Online (Sandbox Code Playgroud)

否则请评论。

https://www.postgresql.org/docs/12/app-pgdump.html