Re: Add a hook for handling logical decoding messages on subscribers.

From: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Ajin Cherian <itsajin(at)gmail(dot)com>, Zhijie Hou <houzhijie22(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add a hook for handling logical decoding messages on subscribers.
Date: 2026-12-01 11:56:40
Message-ID: CABdArM40AvZAcFXM_qVQzyAF=Gj=rT2Lmad=4fmxp+q0E4WakA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 1, 2026 at 12:42 PM Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
>
> On Sat, Nov 21, 2026 at 12:05 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> >
> > On Wed, Nov 18, 2026 at 4:48 PM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
> > >
> >
> > Given that we’ve agreed on the 0001 patch, I’m going to push it early
> > next week, barring any objections. I’d like to hold off on the 0002
> > patch to give it more review time.
> >
>
>
> Hi Sawada-san,
>
> I've started reviewing/testing the hook patch (v10-002)

On further review, I found that GUC changes made by the handler stay
in the apply worker after it returns.
For example, if the handler runs a script with "SET search_path =
public, pg_catalog", later changes are applied with that path instead
of the empty one, so an unqualified upper() in a trigger may resolve
to public.upper() rather than the built-in. The same goes for other
GUCs, e.g. session_replication_role or synchronous_commit.

When a later transaction fails due to this, the worker recovers after
the restart, as the GUCs are reset. But if the SET and the failing
change are in the same remote transaction, the handler runs the SET
again on every retry, and the worker fails in a loop.

It depends on how the handler is written, so it may be rare, but I
could reproduce the loop with an ALWAYS trigger on the subscriber that
calls upper() unqualified, and a public.upper() that raises error
(steps attached).

Maybe we can undo the handler's GUC changes, as below?

apply_handle_message(StringInfo s):
...
+ save_nestlevel = NewGUCNestLevel();
(*LogicalRepMessageHandle_hook) (&msg);
+ AtEOXact_GUC(false, save_nestlevel);
...

--
Thanks,
Nisha

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nisha Moond 2026-12-01 11:59:28 Re: Add a hook for handling logical decoding messages on subscribers.
Previous Message Kirill Reshke 2026-12-01 11:51:27 Re: pg_upgrade: fix use-after-close in cleanup_output_dirs()