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

Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>

From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
To: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Euler Taveira <euler@eulerto.com>, Bertrand Drouvot <bertranddrouvot.pg@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-01-06T11:20:14Z
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 →
  1. Fix regression test failure when wal_level is set to minimal.

  2. Toggle logical decoding dynamically based on logical slot presence.

  3. Disallow server start with sync_replication_slots = on and wal_level < logical.

On Sat, Jan 4, 2025 at 6:03 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote:
>
> On Fri, Jan 3, 2025 at 6:31 AM Euler Taveira <euler@eulerto.com> wrote:
> >
> > On Fri, Jan 3, 2025, at 10:14 AM, Bertrand Drouvot wrote:
> >
> > If we don't want to force wal_level = logical to enable logical decoding (your
> > second idea) then I think that it would be better to "hide" everything behind
> > logical replication slot creation / deletion. That would mean that having at
> > least one logical replication slot created would be synonym to "activate logical
> > decoding" and zero logical replication slot created would be synonym to "deactivate
> > logical decoding".
> >
> >
> > I like this idea. The logical replication slot existence already has the
> > required protections and guarantees (no running transactions from the past while
> > creating) for logical decoding.
>
> I agree that it's better behavior.
>
> >
> > Having said that, you are basically folding 'logical' machinery into 'replica'.
> > The 'logical' option can still exists but it will be less attractive because it
> > increases the WAL volume even if you are not using logical replication. I don't
> > know if the current 'logical' behavior (WAL records for logical decoding even
> > if there is no active logical replication) has any use case (maybe someone
> > inspects these extra records for analysis) but one suggestion (separate patch)
> > is to make 'logical' synonymous with the new 'replica' behavior (logical
> > decoding capability). This opens the door to remove 'logical' in future
> > releases (accepted as synonym but not documented).
>
> To enable the logical decoding automatically when the first slot is
> created, probably we need to do something like:
>
> 1. enable WAL-logging logical info.
> 2. wait for all running transactions to finish.
> 3. enable logical decoding, and write a XLOG_LOGICAL_DECODING_STATUS record,
> 4. create a logical slot
>   4-1. reserve the WAL and write an XLOG_RUNNING_XACTS record.
>   4-2. wait for all transactions in the XLOG_RUNNING_XACTS record to
> finish during creating the initial snapshot.

A naive question: Can we combine step 2 and 4-2 - may be we need to
combine 4-1 and 3 too.

-- 
Best Wishes,
Ashutosh Bapat