Re: adding partitioned tables to publications

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: adding partitioned tables to publications
Date: 2019-11-08 04:27:46
Message-ID: CA+HiwqHf8_bcyHt=6R4O_Ju4P_Wz6wu1MkOAe14URdpdafS_KQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Sorry about the delay.

On Mon, Nov 4, 2019 at 8:00 PM Peter Eisentraut
<peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:
> This patch seems excessively complicated to me. Why don't you just add
> the actual partitioned table to pg_publication_rel and then expand the
> partition hierarchy in pgoutput (get_rel_sync_entry() or
> GetRelationPublications() or somewhere around there). Then you don't
> need to do any work in table DDL to keep the list of published tables up
> to date.

I tend to agree that having to manage this at the DDL level would be
bug-prone, not to mention pretty complicated code to implement it.

I have tried to implement it the way you suggested. So every decoded
change to a leaf partition will now be published not only via its own
publication but also via publications of its ancestors if any. That
irrespective of whether a row is directly inserted into the leaf
partition or got routed to it via insert done on an ancestor. In this
implementation, the only pg_publication_rel entry is the one
corresponding to the partitioned table.

On the subscription side, when creating pg_subscription_rel entries,
for a publication containing a partitioned table, all of its
partitions too must be fetched as being included in the publication.
That is necessary, because the initial syncing copy and subsequently
received changes must be applied to individual partitions. That could
be changed in the future by publishing leaf partition changes as
changes to the actually published partitioned table. That future
implementation will also hopefully take care of the concern that Rafia
mentioned on this thread that even with this patch, one must make sure
that tables match one-to-one when they're in publish-subscribe
relationship, which actually needs us to bake in low-level details
like table's relkind in the protocol exchanges.

Anyway, I've attached two patches -- 0001 is a refactoring patch. 0002
implements the feature.

Thanks,
Amit

Attachment Content-Type Size
0001-Some-refactoring-of-publication-and-subscription-cod.patch application/octet-stream 10.0 KB
0002-Support-adding-partitioned-tables-to-publication.patch application/octet-stream 16.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Lepikhov 2019-11-08 04:33:35 Re: pg_waldump and PREPARE
Previous Message Kyotaro Horiguchi 2019-11-08 04:26:18 Re: pg_waldump and PREPARE