[Proposal] Allow pg_dump to include all child tables with the root table

From: Gilles Darold <gilles(at)migops(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [Proposal] Allow pg_dump to include all child tables with the root table
Date: 2023-01-11 16:59:59
Message-ID: 5aa393b5-5f67-8447-b83e-544516990ee2@migops.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

I would like to propose a new pg_dump option called --with-child to
include or exclude from a dump all child and partition tables when a
parent table is specified using option -t/--table or -T/--exclude-table.
The whole tree is dumped with the root table.

To include all partitions or child tables with inheritance in a table
dump we usually use the wildcard, for example:

    pg_dump -d mydb -t "root_tbname*" > out.sql

This suppose that all child/partition tables use the prefix root_tbname
in their object name. This is often the case but, if you are as lucky as
me, the partitions could have a total different name. No need to say
that for inheritance this is rarely the case. The other problem is that
with the wildcard you can also dump relations that are not concerned at
all by what you want to dump. Using the --with-child option will allow
to just specify the root relation and all child/partition definitions
and/or data will be parts of dump.

    pg_dump -d mydb --table "root_tbname" --with-childs > out.sql

To exclude a whole inheritance tree from a dump:

    pg_dump -d mydb --exclude-table "root_tbname" --with-childs > out.sql

Here in attachment the patch that adds this feature to pg_dump.

Is there is any interest for this feature?

Best regards,

--
Gilles Darold
https://www.migops.com/

Attachment Content-Type Size
0001-dump-with-child-v1.patch text/x-patch 11.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Borodin 2023-01-11 17:13:43 Re: MultiXact\SLRU buffers configuration
Previous Message vignesh C 2023-01-11 16:59:25 Re: mprove tab completion for ALTER EXTENSION ADD/DROP