pg_wait_for_backend_termination()

A function which waits for a backend to terminate
This entry relates to a PostgreSQL feature which is part of PostgreSQL 14, due to be released in late 2021.

pg_wait_for_backend_termination() is a system function which waits for a backend to terminate.

pg_wait_for_backend_termination() was added in PostgreSQL 14.

Usage

pg_wait_for_backend_termination ( pid INTEGER, timeout BIGINT DEFAULT 5000 ) → BOOLEAN

When pg_terminate_backend() is used to attempt termination of a backend, there may be some delay until the backend can be terminated. pg_wait_for_backend_termination() provides a method for clients to determine when the termination takes place.

Note that a timeout value must be supplied; it is not possible to specify an indefinite timeout.

Change history

Examples

postgres=# SELECT pg_wait_for_backend_termination(1268106);
WARNING:  backend with PID 1268106 did not terminate within 5000 milliseconds
 pg_wait_for_backend_termination 
---------------------------------
 f
(1 row)

Time: 5007.215 ms (00:05.007)

Attempting to determine the status of a PID which does not belong to the running PostgreSQL instance:

postgres=# SELECT pg_wait_for_backend_termination(123456);
WARNING:  PID 123456 is not a PostgreSQL server process
 pg_wait_for_backend_termination 
---------------------------------
 f
(1 row)

Categories

Management / adminstration, System function

See also

pg_terminate_backend()