Re: Switch background worker on/off in runtime.

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: "ISHAN CHHANGANI (dot)" <f20200230(at)hyderabad(dot)bits-pilani(dot)ac(dot)in>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Switch background worker on/off in runtime.
Date: 2024-06-02 21:22:07
Message-ID: efd20465-f7bb-4604-b427-4fe27bac5d2f@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 31.05.24 11:28, ISHAN CHHANGANI . wrote:
> Is it possible to switch on/off a background worker in runtime?
>
> worker.bgw_flags =BGWORKER_SHMEM_ACCESS;
>
> worker.bgw_start_time =BgWorkerStart_PostmasterStart;
>
> I want to switch off the worker based on some flag value, etc, either
> from the main process or the worker itself.
>
> Are there any already existing examples?

I think this depends more on your exact use case. For example, the
logical replication background workers have sophisticated logic to do
this. There is a launcher, which is itself a background worker, which
launches other per-subscription workers. And there are commands to
disable subscriptions, which would among other things stop their
corresponding background workers. That logic is specific to the needs
of the logic replication system. You might get some ideas from that.
But in general it will need a bit of custom logic.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-06-02 21:31:03 Re: Schema variables - new implementation for Postgres 15
Previous Message Peter Eisentraut 2024-06-02 21:17:06 Re: pgsql: Add more SQL/JSON constructor functions