pg_terminate_backend()

A function which instructs a backend to terminate

pg_terminate_backend() is a system function which instructs a backend to terminate.

pg_terminate_backend() was added in PostgreSQL 8.0.

Usage

PostgreSQL 14 and later:

pg_terminate_backend ( pid INTEGER, timeout BIGINT DEFAULT 0 ) → BOOLEAN

PostgreSQL 13 and earlier:

pg_terminate_backend ( pid INTEGER ) → BOOLEAN

From PostgreSQL 14, if a backend does not terminate within the specified timeout value, or no timeout value was provided, it is possible to use the function pg_wait_for_backend_termination() to wait for the backend to terminate.

Change history

Examples

Termination of a PostgreSQL backend:

postgres=# SELECT pg_terminate_backend(1306214);
 pg_terminate_backend 
----------------------
 t
(1 row)

Attempting terminate a PID which does not belong to the running PostgreSQL instance:

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

Categories

Management / adminstration, System function

See also

pg_cancel_backend()