Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding sequences from pg_dump

I'm creating an export of a postgres database (10.1) with some tables excluded. I followed the instructions in Is there a way to get pg_dump to exclude a specific sequence?. However, sequences for the excluded tables are still included. Is there a way to make sure they're kept out?

To isolate the problem, I created a small sample database with a table called include and exclude, added a single row to each table, and used this command to export the database:

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

The dump did not include the exclude table, but it did include the sequence:

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

CREATE SEQUENCE exclude_id_seq
...
like image 636
Matt Hampel Avatar asked Dec 17 '22 21:12

Matt Hampel


1 Answers

You should be able to exclude the sequence explicitly using another --exclude-table:

--exclude-table=exclude_id_seq

Which should end up looking like this:

$ 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
like image 122
Michael Powers Avatar answered Jan 07 '23 16:01

Michael Powers