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

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Nisha Moond <nisha(dot)moond412(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-03 20:25:38
Message-ID: CAD21AoAkd==11N94u7n-RDLdQCFO2FXOb+kv8gGtsn6eWipBSw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 1, 2026 at 3:56 AM Nisha Moond <nisha(dot)moond412(at)gmail(dot)com> wrote:
>
> 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?

I'm not sure we should have such a treatment for this hook. IIUC it's
an extension responsibility. We have a number of hook functions but no
one ensures to restore the changed GUC parameters.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2026-12-03 20:28:51 Re: test: avoid redundant standby catchup in 049_wait_for_lsn
Previous Message Masahiko Sawada 2026-12-03 20:22:12 Re: Add a hook for handling logical decoding messages on subscribers.