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>, "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-10-23T18:52:54Z
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, Oct 23, 2025 at 3:39 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> Please find a few comments:
>
> 1)
> RequestDisableLogicalDecoding:
> Shall we have 'Assert(!MyReplicationSlot)' here to ensure that this
> function is invoked after we have released and dropped the slot. This
> is similar to 'Assert(MyReplicationSlot)' in
> EnsureLogicalDecodingEnabled().
I think the reason why we need 'Assert(MyReplicationSlot)' in
EnsureLogicalDecodingEnabled() is that otherwise the caller cannot get
the expected result. IOW, suppose w can call
EnsureLogicalDecodingEnabled() without holding a logical slot, logical
decoding is not enabled if all logical slots are dropped concurrently
in spite of the function name having the term "Ensure". As for
RequestDisableLogicalDecoding(), it can request to disable logical
decoding even while holding a logical slot. It might practically make
less sense but it's no problem in principle. I guess it makes sense to
put the assertion into DisableLogicalDecodingIfNecessary() instead.
>
> 2)
> EnsureLogicalDecodingEnabled sets status_change_inprogress to false
> before writing the WAL record. Initially, I thought this could lead to
> a situation where another session might drop the same slot, since
> there’s nothing preventing it (as status_change_inprogress is false
> and LogicalDecodingControlLock has been released). This could, in
> theory, result in the checkpointer writing the WAL record that
> disables logical decoding before EnsureLogicalDecodingEnabled() writes
> its WAL record that enables it — potentially causing an issue. But
> this problem could not be reproduced in practice, since the slot was
> acquired by session1, and therefore another session attempting to drop
> it couldn’t acquire it. That said, I still lean towards setting
> status_change_inprogress = false after the WAL record has been written
> in EnsureLogicalDecodingEnabled(). Thoughts?
> If not, we could add a comment explaining why this scenario is not a problem.
Good point. I'll incorporate your suggestion.
>
> 3)
> + # Drop the logical slot, requesting to disable logical decoding to
> the checkpointer.
> + # It has to wait for the recovery to complete before disabling
> logical decoding.
> + $standby5->safe_psql('postgres',
> + qq[select pg_drop_replication_slot('standby5_slot');]);
> +
> + # Resume the startup process to complete the recovery.
> + $standby5->safe_psql('postgres',
> + qq[select injection_points_wakeup('startup-logical-decoding-status-change-end-of-recovery')]
> + );
> +
> + $standby5->wait_for_log(
> + "waiting for recovery completion to change logical decoding status");
>
> Shouldn’t we check the log for "waiting for recovery completion..."
> before triggering injection_points_wakeup?
>
> IIUC, the current order may cause intermittent failures. Imagine that
> drop-slot has not yet reached the LogicalDecodingStatusChangeAllowed
> and RecoveryInProgress checks, and we release the injection point in
> the meantime. In that case, drop-slot may never end up waiting, and we
> might not see the expected log message.
Agreed.
I'll self-review the patch again and share the updated version patch.
Regards,
--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com