Re: A new function to wait for the backend exit after termination
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: Magnus Hagander <magnus@hagander.net>, PostgreSQL-development <pgsql-hackers@postgresql.org>,
Fujii Masao <masao.fujii@oss.nttdata.com>
Date: 2020-10-22T02:46:18Z
Lists: pgsql-hackers
Thanks for the feedback. On Wed, Oct 21, 2020 at 8:01 PM David G. Johnston <david.g.johnston@gmail.com> wrote: > > On Wed, Oct 21, 2020 at 6:13 AM Magnus Hagander <magnus@hagander.net> wrote: >> >> I think it would be nicer to have a pg_terminate_backend(pid, wait=false), so a function with a second parameter which defaults to the current behaviour of not waiting. And it might be a good idea to also give it a timeout parameter? > > Agreed on the overload, and the timeouts make sense too - with the caller deciding whether a timeout results in a failure or a false return value. > If the backend is terminated within the user specified timeout then the function returns true, otherwise false. > >>> 2. pg_wait_backend() -- which waits for a given backend process. Note that this function has to be used carefully after pg_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. > > Is there a requirement for waiting to be superuser only? You are not affecting any session but your own during the waiting period. > IIUC, in the same patch instead of returning an error in case of non-superusers, do we need to wait for user provided timeout milliseconds until the current user becomes superuser and then throw error if still non-superuser, and proceed further if superuser? Do we need to have a new function that waits until a current non-superuser in a session becomes superuser? Something else? > > I could imagine, in theory at least, wanting to wait for a backend to go idle as well as for it disappearing. Scope creep in terms of this patch's goal but worth at least considering now. > IIUC, do we need a new option, something like pg_wait_backend(pid, timeout, waituntil) where "waituntil" if specified "idle" waits until the given backend goes to idle mode, or "termination" waits until termination? If my understanding is wrong, could you please explain more?
Commits
-
Copy-edit text for the pg_terminate_backend() "timeout" parameter.
- 0aac73e6a260 14.0 landed
-
Remove pg_wait_for_backend_termination().
- 5f1df62a459b 14.0 landed
-
Add functions to wait for backend termination
- aaf043257205 14.0 landed
-
Fix typo in comment.
- 6742e14959a3 14.0 cited