On Tue, Feb 11, 2025 at 11:44 PM Bertrand Drouvot <bertranddrouvot...@gmail.com> wrote: > > Hi, > > On Tue, Feb 11, 2025 at 02:11:10PM -0800, Masahiko Sawada wrote: > > I've updated the patch that includes comment updates and bug fixes. > > Thanks! > > > The main idea of changing WAL level online is to decouple two aspects: > > (1) the information included in WAL records and (2) the > > functionalities available at each WAL level. With that, we can change > > the WAL level gradually. For example, when increasing the WAL level > > from 'replica' to 'logical', we first switch the WAL level on the > > shared memory to a new higher level where we allow processes to write > > WAL records with additional information required by the logical > > decoding, while keeping the logical decoding unavailable. The new > > level is something between 'replica' and 'logical'. Once we confirm > > all processes have synchronized to the new level, we increase the WAL > > level further to 'logical', allowing us to start logical decoding. The > > patch supports all combinations of WAL level transitions. It makes > > sense to me to use a background worker to proceed with this transition > > work since we need to wait at some points, rather than delegating it > > to the checkpointer process. > > The background worker being added is "wal_level control worker". I wonder if > it would make sense to create a more "generic" one instead (to whom we could > assign more "tasks" later on, as suggested in the past in [1]). > > + /* > + * XXX: Perhaps it's not okay that we failed to launch a bgworker and give > + * up wal_level change because we already reported that the change has > + * been accepted. Do we need to use aux process instead for that purpose? > + */ > + if (!RegisterDynamicBackgroundWorker(&bgw, &bgw_handle)) > + ereport(WARNING, > + (errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED), > + errmsg("out of background worker slots"), > + errhint("You might need to increase \"%s\".", > "max_worker_processes"))); > > Not sure it has to be an aux process instead as it should be busy in rare > occasions.
Thank you for referring to the custodian worker thread. I'm not sure that online wal_level change work would fit the concept of custodian worker, which offloads some work for time-critical works such as checkpointing, but this idea made me think of other possible directions of this work. Looking at the latest custodian worker patch, the basic architecture is to have a single custodian worker and processes can ask it for some work such as removing logical decoding related files. The online wal_level change will be the one of the tasks that processes (eps. checkpointer) can ask for it. On the other hand, one point that I think might not fit this wal_level work well is that while the custodian worker is a long-lived worker process, it's sufficient for the online wal_level change work to have a bgworker that does its work and then exits. IOW, from the perspective of this work, I prefer the idea of having one short-lived worker for one task over having one long-lived worker for multiple tasks. Reading that thread, while we need to resolve the XID wraparound issue for the work of removing logical decoding related files, the work of removing temporary files seems to fit a short-lived worker style. So I thought as one of the directions, it might be worth considering to have an infrastructure where we can launch a bgworker just for one task, and we implement the online wal_level change and temporary files removal on top of it. > Maybe we could add some mechanism for ensuring that a bgworker slot is > available > when needed (as suggested in [2])? Yeah, we need this mechanism if we use a bgworker for these works. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com