Re: POC: enable logical decoding when wal_level = 'replica' without a server restart

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Date: 2025-12-01 07:02:59
Message-ID: CAD21AoAAEfOu5LsZrPfG=_7PSUtbydru+c1dF=zRCCsHJC7dng@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 1, 2025 at 12:20 AM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> On Thu, Nov 27, 2025 at 11:23 PM vignesh C <vignesh21(at)gmail(dot)com> wrote:
> >
> >
> > Few comments:
> > 1) There is no validation after creation of temporary logical
> > replication slot, can we see if "logical decoding is enabled upon
> > creating a new logical replication slot" is logged as a validation for
> > this:
> > +# Create a temporary logical slot but exits without releasing it explicitly.
> > +# This enables logical decoding but skips disabling it and delegates to the
> > +# checkpointer.
> > +$primary->safe_psql('postgres',
> > + qq[select pg_create_logical_replication_slot('test_tmp_slot',
> > 'test_decoding', true)]
> > +);
> > +
> > +# Wait for the checkpointer to disable logical decoding.
> > +wait_for_logical_decoding_disabled($primary);
> >
> > I had a look at the header file inclusions in the patch and found few
> > issues with it:
> > 2) Here logicalctl.h should be included before logicallauncher.h:
> > #include "postmaster/interrupt.h"
> > #include "replication/logicallauncher.h"
> > +#include "replication/logicalctl.h"
> > #include "replication/slotsync.h"
> >
> > 3) I was able to compile without inclusion of logicalctl.h, may be it
> > is not required because we include origin.h which includes xlog.h
> > which includes logicalctl.h already:
> > diff --git a/src/backend/access/transam/xlog.c
> > b/src/backend/access/transam/xlog.c
> > index 22d0a2e8c3a..6f3f10af8fd 100644
> > --- a/src/backend/access/transam/xlog.c
> > +++ b/src/backend/access/transam/xlog.c
> > @@ -79,7 +79,9 @@
> > #include "postmaster/walsummarizer.h"
> > #include "postmaster/walwriter.h"
> > #include "replication/origin.h"
> > +#include "replication/logicalctl.h"
> >
> > 4) Similarly it is not required in checkpointer.c, logical.c,
> > logicalctl.c, slotsync.c, slot.c, slotfuncs.c, walsender.c, ipci.c,
> > procsignal.c, standby.c and postinit.c
> >
> > 5) Few comments in the test file exceeds 80 chars, if possible we can
> > move it to the next line:
> > 5.a) +# Create and drop another logical slot, then check if
> > effective_wal_level remains
> > +# 'logical'.
> > 5.b) +# Add other settings to test if we disable logical decoding when
> > invalidating the last
> > +# logical slot.
> > 5.c) # Check if logical decoding is disabled after invalidating the
> > last logical slot.
> > 5.d) # Check if effective_wal_level is increased to 'logical' on the
> > cascaded standby.
> > 5.e) # Check that the logical decoding is not enabled on the standby4.
> > Note that it still has
> > # the invalidated logical slot.
> > 5.f) # Restart the primary with setting wal_level = 'logical' and
> > create a new logical
> > # slot.
> > 5.g) # Drop the logical slot, requesting to disable logical decoding
> > to the checkpointer.
> > 5.h) # Test the abort process of logical decoding activation. We drop
> > the primary's
> > # slot to decrease its effective_wal_level to 'replica'.
>
> I've fixed the above points and run pgperltidy again. I'll submit the
> updated patch soon.
>

I've attached the patch. All the comments I got so far have been
addressed in this version unless I'm missing something.

Regards,

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

Attachment Content-Type Size
v31-0001-Toggle-logical-decoding-dynamically-based-on-log.patch application/octet-stream 104.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-12-01 07:03:49 Re: alignas (C11)
Previous Message Michael Paquier 2025-12-01 07:01:52 Re: Refactoring: Use soft error reporting for *_opt_overflow functions of date/timestamp