Re: Proposal: Conflict log history table for Logical Replication

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Zhijie Hou <houzhijie22(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shihao zhong <zhong950419(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, saurabh singh <saurabh(dot)singh214(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, shveta malik <shvetamalik(at)gmail(dot)com>
Subject: Re: Proposal: Conflict log history table for Logical Replication
Date: 2026-11-25 06:53:20
Message-ID: CAJpy0uDxtfYGqfU73uDRAytJC=t6PneivzmErv=my3iNjhjbSA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 25, 2026 at 11:48 AM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Wed, Nov 25, 2026 at 11:13 AM Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
> >
> > On Wed, Nov 25, 2026 at 10:43 AM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> > >
> > > On Fri, Nov 20, 2026 at 4:38 PM Hayato Kuroda (Fujitsu)
> > > <kuroda(dot)hayato(at)fujitsu(dot)com> wrote:
> > > >
> > > > > Here is the V96 version which:
> > > >
> > > > Thanks for updating the patch. I reviewed v96-0001 and LGTM.
> > > >
> > >
> > > Thanks for the review and sorry I forgot to credit you as a reviewer.
> > > I have pushed the patch.
> > >
> > > I have one comment
> > > > for codes in HEAD, let me share just in case.
> > > >
> > > > ```
> > > > /* Create conflict log table. */
> > > > relid = heap_create_with_catalog(relname,
> > > > PG_CONFLICT_NAMESPACE,
> > > > 0, /* tablespace */
> > > > ...
> > > > ```
> > > >
> > > > In create_conflict_log_table() the tablespace is specified as 0, it bypasses a GUC
> > > > default_tablespace. Is it intentional? The parameter can be resolved by
> > > > GetDefaultTablespace().
> > > >
> > >
> > > Yes, the current behavior is intentional and I feel that is
> > > appropriate. This is because using default_tablespace will make it
> > > depend on the session that creates it rather than keeping it tied with
> > > subscriptions. Also, this is a system-managed table, so it seems apt
> > > to keep it at database's default tablespace. The other thing is the
> > > privileges mismatch. The DefineRelation() that uses
> > > GetDefaultTablespace() checks ACL_CREATE on the tablespace for the
> > > current user, while the table is owned by the subscription owner
> > > (subowner), so we need to consider that differently.
> > >
> > > > Even if we retain the behavior, it can be InvalidOid
> > > >
> > >
> > > Agreed. Additionally, we can add a comment on the lines: "Place the
> > > table in the database's default tablespace, ignoring
> > > default_tablespace, so its placement does not depend on the session
> > > that creates it.". What do you think?
> > >
> >
> > Please find attached patch with the comment change suggested above. It
> > also combines a few pending fixes for commit a5918fddf1:
> > 1) The missing pg_subscription column entries in catalogs.sgml, and
> > some code comment rewrites from [1].
> > 2) The issue reported by Zsolt and the fix he provided at [2]
> >
> > [1] https://www.postgresql.org/message-id/CAFiTN-sHeA%3DA%2B054KcOGue_q4tiT65rRvKxfdmJL3xjMwa2Kow%40mail.gmail.com
> > [2] https://www.postgresql.org/message-id/CAN4CZFNaWLs6rAOX3KNzgQ0ci-6PB%2BmWJNj_6_F-O_vomb8Euw%40mail.gmail.com
> >
>
> Thanks for the patch Nisha. I have just started the reveiw, and
> noticed thatthe patch moves the drop_sub_conflict_log_table() call in
> DropSubscription() from 'after' the prepared-transaction check to
> 'before' it. Won't this reintroduce the hang that check was
> specifically added to prevent? As I understand it, if a prepared
> transaction holds a lock on the conflict log table, the drop now takes
> AccessExclusiveLock on the table and blocks before we ever reach the
> check. Isn't it?
>

Let me clarify the situation. It depends on whether the apply worker
is running, because the drop now also happens before the worker is
stopped:

With the worker still running (enabled), the DROP hangs on the
conflict log table lock, but it later clears on its own once the
prepared transaction is resolved.

With the subscription disabled before the DROP-SUB (or the worker
otherwise gone), the DROP hangs and does not clear by itself. There's
no worker to apply a resolution from the publisher, and trying to
re-enable the sub in the meantime just blocks on the same subscription
lock DROP holds, so no new worker can start.

Earlier the check raised the error before we actually dropped the
table, which seems better to me than blocking on the lock.

Shall we move the drop_sub_conflict_log_table() call to just after the
prepared-transaction check? IIUC it would still be before the
non-transactional cleanup (the replication slot drop on the
publisher), so it should also satisfy the reason given in the commit
message for moving it up.

thanks
Shveta

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-11-25 06:54:16 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Michael Paquier 2026-11-25 06:43:54 Re: Infinite loop in XLogPageRead() on standby