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: PostgreSQL-development <pgsql-hackers@postgresql.org>,
Fujii Masao <masao.fujii@oss.nttdata.com>
Date: 2020-10-21T13:02:15Z
Lists: pgsql-hackers
Attachments
- v1-0001-pg_terminate_backend_and_wait.patch (application/x-patch) patch v1-0001
Hi, Currently pg_terminate_backend(), sends SIGTERM to the backend process but doesn't ensure it's exit. There are chances that backends still are running(even after pg_terminate_backend() is called) until the interrupts are processed(using ProcessInterrupts()). This could cause problems especially in testing, for instance in a sql file right after pg_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. 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. Attaching a WIP patch herewith. Thoughts? [1] https://www.postgresql.org/message-id/flat/f31cc4da-a7ea-677f-cf64-a2f9db854bf5%40oss.nttdata.com With Regards, Bharath Rupireddy. EnterpriseDB: http://www.enterprisedb.com
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