Re: How to only auto-restart BGW only on crash or _PG_init

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: How to only auto-restart BGW only on crash or _PG_init
Дата
Msg-id CA+TgmoZFWCsPjbbT1vq3NA6hK7QRrBpOX8Tpk_qnGD6Zs3_Yow@mail.gmail.com
обсуждение исходный текст
Ответ на How to only auto-restart BGW only on crash or _PG_init  (Jeremy Finzel <finzelj@gmail.com>)
Список pgsql-hackers
On Tue, Mar 24, 2020 at 2:33 PM Jeremy Finzel <finzelj@gmail.com> wrote:
> I would be grateful for some direction on how to use Background workers to have a worker automatically restart *only*
incertain cases, i.e. on postmaster start (_PG_init) or a soft crash.  I run into all sorts of trouble if I set
bgw_restart_timeto actually restart on sigterm, because in most cases I don't want it to restart (i.e. it was launched
withinvalid config, the SQL becomes invalid...).  But I *do* want it to auto-restart in any kind of crash.  If I set
bgw_restart_timeto never restart, then it doesn't restart after a soft crash, which I want. 
>
> This is for my extension pglogical_ticker, and specifically within this main function where a sigterm might happen:
> https://github.com/enova/pglogical_ticker/blob/ef9b68fd6b5b99787034520009577f8cfec0049c/pglogical_ticker.c#L85-L201
>
> I have tried several things unsuccessfully (checking result of SPI_execute or SPI_connect) , usually resulting in a
constantlyrestarting and failing worker.  So, is there a straightforward way to only have the worker auto-restart in a
verynarrow range of cases? 

I think what you can do is configure the worker to always restart, but
then have it exit(0) in the cases where you don't want it to restart,
and exit(1) in the cases where you do want it to restart.  See:

https://git.postgresql.org/pg/commitdiff/be7558162acc5578d0b2cf0c8d4c76b6076ce352

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: Add A Glossary
Следующее
От: Andres Freund
Дата:
Сообщение: Re: Adding a test for speculative insert abort case