pg_cancel_backend()

A function which cancels a backend's current query

pg_cancel_backend() is a system function which cancels the current query in the specified backend.

pg_cancel_backend() was added in PostgreSQL 8.0.

Usage

pg_cancel_backend ( pid integer ) → boolean

Change history

Examples

Instructing a backend to cancel the current query:

postgres=# SELECT pg_cancel_backend(1308332);
 pg_cancel_backend 
-------------------
 t
(1 row)

The affected backend:

postgres=# SELECT pg_backend_pid();
 pg_backend_pid 
----------------
        1308332
(1 row)

postgres=# INSERT INTO foo VALUES(generate_series(1,100000000));
ERROR:  canceling statement due to user request

Categories

Management / adminstration, System catalogue

See also

pg_terminate_backend()