Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Masahiko Sawada <sawada.mshk@gmail.com>
From: Masahiko Sawada <sawada.mshk@gmail.com>
To: shveta malik <shveta.malik@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>,
Peter Smith <smithpb2250@gmail.com>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>,
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>, Shlok Kyal <shlok.kyal.oss@gmail.com>,
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-12-01T06:17:34Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix regression test failure when wal_level is set to minimal.
- 0de5f0d869d1 19 (unreleased) landed
-
Toggle logical decoding dynamically based on logical slot presence.
- 67c20979ce72 19 (unreleased) landed
-
Disallow server start with sync_replication_slots = on and wal_level < logical.
- 12da45742cfd 19 (unreleased) cited
On Thu, Nov 27, 2025 at 11:00 PM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Thu, Nov 27, 2025 at 4:33 PM shveta malik <shveta.malik@gmail.com> wrote:
> >
> > A few more comments:
> >
> >
> > 10)
> > +# Promote standby3, increasing effective_wal_level to 'logical' as
> > its wal_level
> > +# is set to 'logical'.
> > +$standby3->promote;
> > +
> > +# Check if effective_wal_level is increased to 'logical' on the
> > cascaded standby.
> > +$standby3->wait_for_replay_catchup($cascade);
> > +test_wal_level($cascade, "replica|logical",
> > + "effective_wal_level got increased to 'logical' on standby as the
> > new primary has wal_level='logical'"
> > +);
> >
> > The message is slightly confusing due to usage of both 'standby' and
> > 'new primary'. Can we make it:
> > effective_wal_level got increased to 'logical' as the new primary has
> > wal_level='logical'
> >
>
> Upon reconsideration, we can keep it as is. I understand the intent now.
Okay.
>
> ===
>
> I tried to test possible race-scenarios (known to me), they seem to
> work well, except one minor thing:
>
> Let's say there is slot1 present, backend1 is trying to drop slot1 and
> backend2 is trying to create slot2.
>
> DisableLogicalDecodingIfNecessary() first kicks in and reaches the
> stage where it has disabled and released the lock. Before it could
> EmitSignal and log, EnsureLogicalDecodingEnabled() kicks in and
> completes its execution.
> In such a case we end up with reverse LOG messages in log file:
>
> 09:47:16.489 IST LOG: logical decoding is enabled upon creating a new
> logical replication slot
> 09:47:17.484 IST LOG: logical decoding is disabled because there are
> no valid logical replication slots
>
> while logical decoding is actually enabled in the system.
>
> Shall we check 'if (!LogicalDecodingCtl->xlog_logical_info)' before
> logging in DisableLogicalDecodingIfNecessary()?
>
In DisableLogicalDecodingIfNecessary(), we have (without comments):
if (!LogicalDecodingCtl->xlog_logical_info || CheckLogicalSlotExists())
{
LogicalDecodingCtl->pending_disable = false;
LWLockRelease(LogicalDecodingControlLock);
return;
}
START_CRIT_SECTION();
LogicalDecodingCtl->logical_decoding_enabled = false;
write_logical_decoding_status_update_record(false);
LogicalDecodingCtl->xlog_logical_info = false;
LogicalDecodingCtl->pending_disable = false;
LWLockRelease(LogicalDecodingControlLock);
END_CRIT_SECTION();
EmitProcSignalBarrier(PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO);
ereport(LOG,
errmsg("logical decoding is disabled because there are no
valid logical replication slots"));
Does it make sense to reorder them to the following?
START_CRIT_SECTION();
LogicalDecodingCtl->logical_decoding_enabled = false;
write_logical_decoding_status_update_record(false);
LogicalDecodingCtl->xlog_logical_info = false;
LogicalDecodingCtl->pending_disable = false;
END_CRIT_SECTION();
ereport(LOG,
errmsg("logical decoding is disabled because there are no
valid logical replication slots"));
LWLockRelease(LogicalDecodingControlLock);
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com