Re: Improve logical replication usability when tables lack primary keys

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Improve logical replication usability when tables lack primary keys
Date: 2025-12-15 05:48:14
Message-ID: CAA4eK1KzjxO-qWjWSox6e6AWH4FVU5ZPEgeZ+na=eyov7umutg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 15, 2025 at 9:06 AM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> > On Dec 15, 2025, at 11:28, Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
> >
> > On Tue, Nov 11, 2025 at 6:11 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> >>
> >> Hi Amit,
> >>
> >> Thanks for asking.
> >>
> >>> On Nov 11, 2025, at 19:18, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> >>>
> >>> On Mon, Nov 10, 2025 at 1:36 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> >>>>
> >>>> * BACKGROUND
> >>>>
> >>>> This requirement comes from several users operating large deployments, particularly in HIS (Hospital Information Systems). The situation can be summarized as follows:
> >>>>
> >>>> - A central DB operations team maintains the main database and configures logical replication for all tables.
> >>>> - Multiple third-party application vendors are allowed to create new tables in that database.
> >>>> - Some of these newly created tables lack a primary key. Since logical replication with `REPLICATION IDENTITY DEFAULT` requires a primary key, such tables silently fail to replicate.
> >>>> - The DB operations team must then spend significant effort identifying the affected tables and correcting them manually.
> >>>>
> >>>
> >>> Can you share an example of how we silently fail to replicate? Won't
> >>> in such cases UPDATE/DELETE will anyway raise an ERROR?
> >>>
> >>
> >> Yes, UPDATE/DELETE will fail. That’s the easy case to expose the error. Actually my patch will allow the update/delete.
> >>
> >> However, some tables, like dictionary tables, they are important, but don’t have much update/delete, they may silently fail to replicate.
> >
> > But other than UPDATE/DELETE for what operation we need RI, I mean
> > INSERT would work without any RI and UPDATE/DELETE will fail on the
> > publisher itself without setting RI, so can you explain the exact case
> > where it will silently fail to replicate?
> >
>
> Thanks for asking. When fallback to FULL, UPDATE/DELETE will be allowed in the publisher side. In my first email, attached v1 patch is a PoC that has implemented the logic.
>

So, without patch, there is no way we can silently replicate the
UPDATE/DELETE. Ideally, users should alter the tables and make RI as
FULL in such cases if they don't have PK for such tables. Falling back
to FULL for DEFAULT when the table doesn't have PK based on GUC has a
downside that it will increase WAL volume by a large amount. I think
it should be done specific to tables that users want to replicate. I
don't know what is a good way to give to users who don't want to do
the required setup but if we really want to provide something, it is
better to allow such a thing via the publication option instead. I
think it would be good to do such an enhancement if we have more
community support and some other users also appreciate such a feature.
Otherwise, adding something which is specific to a particular user
sounds like a recipe of maintenance burden especially when we already
provide a way to achieve the same thing as is required by the user.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2025-12-15 06:00:16 Re: [PING] fallocate() causes btrfs to never compress postgresql files
Previous Message Chao Li 2025-12-15 05:45:10 Re: Fix memory leak in gist_page_items() of pageinspect