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

From Hayato Kuroda (Fujitsu)
Subject RE: POC: enable logical decoding when wal_level = 'replica' without a server restart
Date
Msg-id OSCPR01MB14966C5E31CA0ACAD07AF8B5FF524A@OSCPR01MB14966.jpnprd01.prod.outlook.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>)
Responses Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
List 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


pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: track generic and custom plans in pg_stat_statements
Next
From: Richard Guo
Date:
Subject: Re: Reduce "Var IS [NOT] NULL" quals during constant folding