Re: A new function to wait for the backend exit after termination
От | Bharath Rupireddy |
---|---|
Тема | Re: A new function to wait for the backend exit after termination |
Дата | |
Msg-id | CALj2ACXeCO+92Dj72Hykbd9DNXUg1QpSk2FDy_AGqj7U3eHTuA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: A new function to wait for the backend exit after termination (Magnus Hagander <magnus@hagander.net>) |
Список | pgsql-hackers |
Thanks for the feedback. On Wed, Oct 21, 2020 at 6:43 PM Magnus Hagander <magnus@hagander.net> wrote: > >> Currently pg_terminate_backend(), sends SIGTERM to the backend process but doesn't ensure it's exit. There are chancesthat backends still are running(even after pg_terminate_backend() is called) until the interrupts are processed(usingProcessInterrupts()). This could cause problems especially in testing, for instance in a sql file right afterpg_terminate_backend(), if any test case depends on the backend's non-existence[1], but the backend is not terminated.As discussed in [1], we have wait_pid()(see regress.c and sql/dblink.sql), but it's not usable across the system.In [1], we thought it would be better to have functions ensuring the backend's exit on the similar lines of pg_terminate_backend(). >> >> I propose to have two functions: >> >> 1. pg_terminate_backend_and_wait() -- which sends SIGTERM to the backend and wait's until it's exit. > > I think it would be nicer to have a pg_terminate_backend(pid, wait=false), so a function with a second parameter whichdefaults to the current behaviour of not waiting. And it might be a good idea to also give it a timeout parameter? > +1 to have pg_terminate_backend(pid, wait=false, timeout), timeout in milliseconds only valid if wait = true. > >> 2. pg_wait_backend() -- which waits for a given backend process. Note that this function has to be used carefully afterpg_terminate_backend(), if used on a backend that's not ternmited it simply keeps waiting in a loop. > > It seems this one also very much would need a timeout value. > > And surely we should show some sort of wait event when it's waiting. > Yes for this function too we can have a timeout value. pg_wait_backend(pid, timeout), timeout in milliseconds. I think we can use WaitLatch with the given timeout and with a new wait event type WAIT_EVENT_BACKEND_SHUTDOWN instead of pg_usleep for achieving the given timeout mechanism. With WaitLatch we would also get the waiting event in stats. Thoughts? rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, timeout, WAIT_EVENT_BACKEND_SHUTDOWN); With Regards, Bharath Rupireddy. EnterpriseDB: http://www.enterprisedb.com
В списке pgsql-hackers по дате отправления: