Re: POC: enable logical decoding when wal_level = 'replica' without a server restart - Mailing list pgsql-hackers

From shveta malik
Subject Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Date
Msg-id CAJpy0uC0e=J7L4q9RnQ3pbSAtvWy40r9qp3tr41zoogHQmDO8g@mail.gmail.com
Whole thread Raw
In response to Re: POC: enable logical decoding when wal_level = 'replica' without a server restart  (Masahiko Sawada <sawada.mshk@gmail.com>)
List pgsql-hackers
On Tue, Jul 15, 2025 at 10:37 PM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> I've attached updated patches that implement the idea we've discussed.
> The patches still need to be polished but the implemented ideas seem
> good. Feedback is very welcome.
>

Thank You for the patches. I just tried my hands on ptach001 yet, few concerns:

1)
+ else if (xlrec.wal_level == WAL_LEVEL_REPLICA &&
+ pg_atomic_read_u32(&ReplicationSlotCtl->n_inuse_logical_slots) == 0)
+ {
+ /*
+ * Disable the logical decoding if there is no in-use logical slot
+ * on the standby.
+ */
+ UpdateLogicalDecodingStatus(false);
+ }

Due to above logic, the change in wal_level to replica on primary may
end up disabling logical decoding on standby, even if logical decoding
is still enabled on primary due to existence of slot.

Steps:
a) Create a slot on primary, but no slots on standby.
b) Switch wal_level to logical on primary by doing a restart.
c) Now switch wal_level back to replica on primary. This will end up
disabling logical decoding on standby and slot creation will fail on
standby as well.

2)
In the same code, why don't we invalidate slots as we do when we
receive XLOG_LOGICAL_DECODING_STATUS_CHANGE?

3)
+ EnsureLogicalDecodingEnabled();

I do not understand the usage of above in synchronize_one_slot().
Since 'EnsureLogicalDecodingEnabled' is a no-op for standby, it will
do nothing here.

4)
- if (wal_level < WAL_LEVEL_LOGICAL)
- ereport(ERROR,
- errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("replication slot synchronization requires \"wal_level\" >=
\"logical\""));
+ if (!IsLogicalDecodingEnabled())
+ ereport(elevel,
+ errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+

Is the change from 'ERROR' to  'elevel' intentional? With this change,
slotsync worker will keep running even if logical decoding is not
enabled on standby (or primary) yet.


thanks
Shveta



pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: Logical Replication of sequences
Next
From: D Laaren
Date:
Subject: Resetting recovery target parameters in pg_createsubscriber