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

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'Masahiko Sawada' <sawada(dot)mshk(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: RE: POC: enable logical decoding when wal_level = 'replica' without a server restart
Date: 2025-07-30 07:22:36
Message-ID: OSCPR01MB14966C5E31CA0ACAD07AF8B5FF524A@OSCPR01MB14966.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Sawada-san,

While reading more, I found a race condition. In this case the effective_wal_level
can be logical even when there is no logical slot.
UpdateLogicalDecodingStatusEndOfRecovery() checks the number of slots of the logical
slot then release the lock once. Then startup process acquires the lock once and
compare with IsLogicalDecodingEnabled(), then update the status afterward if needed.
So, wal_level can be inconsistent if the status is changed after the n_logical_slots
is read.

Steps:
a) constructed a primary-standby system
b) createad a logical slot on the primary
c) createad a logical slot on the standby
d) sent a promote signal to standby
e) dropped a logical slot on standby, just after startup process released
LogicalDecodingControlLock in UpdateLogicalDecodingStatusEndOfRecovery().

After the above, effective_wal_level was keep turning on. Is it the expected behavior?
```
postgres=# SELECT slot_name FROM pg_replication_slots ;
slot_name
-----------
(0 rows)

postgres=# show effective_wal_level ;
effective_wal_level
---------------------
logical
(1 row)

postgres=# SELECT pg_is_in_recovery ();
pg_is_in_recovery
-------------------
f
(1 row)
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2025-07-30 07:55:43 Re: Reduce "Var IS [NOT] NULL" quals during constant folding
Previous Message Michael Paquier 2025-07-30 07:20:28 Re: track generic and custom plans in pg_stat_statements