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-04 05:04:29
Message-ID: CABdArM6ehfFSF+5u5+Dd6PGMhnXPXZKyQEU-nPUH0FbuS-1kyw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Dec 4, 2026 at 1:56 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> 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.
>

Fair point. Then maybe a short note in the hook comment would help,
say that the handler should restore any GUC it changes, since
otherwise it affects how later changes are applied. The comment
already mentions the empty search_path, so it could go next to that.

--
Thanks,
Nisha

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Atsushi Torikoshi 2026-12-04 05:21:24 Re: Why is the LSN reported for pg_logical_emit_message() different from other decoded operations?
Previous Message Nisha Moond 2026-12-04 05:04:12 Re: Add a hook for handling logical decoding messages on subscribers.