Updated on 2025-08-25 GMT+08:00

Server Signaling Functions

Server signaling functions send control signals to other server processes. Only system administrators can use these functions.

pg_cancel_backend(pid int)

Description: Cancels a current query of the backend.

Return type: Boolean.

Note: pg_cancel_backend sends a query cancellation signal (SIGINT) to the backend process identified by pid. The PID of an active backend process can be found in the pid column of the pg_stat_activity view, or can be found by listing the database process using ps on the server.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT pid FROM pg_stat_activity WHERE stmt_type ='RESET';
       pid
-----------------
 281471222065200
(1 row)

SELECT pg_cancel_backend(281471222065200);
 pg_cancel_backend
-------------------
 t
(1 row)

pg_terminate_backend(pid int)

Description: Terminates a backend thread.

Return type: Boolean.

Note: Each of these functions returns true if they are successful and false otherwise.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
postgres=#SELECT pid FROM pg_stat_activity;
       pid       
-----------------
 140657876268816
 140433774061312
 140433587902208
 140433656592128
 140433723717376
 140433637189376
 140433552770816
 140433481983744
 140433349310208
(9 rows)

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

pg_cancel_query(queryId int)

Description: Cancels a current query of the backend. This function is supported in 8.1.2 or later.

Return type: Boolean.

Note: pg_cancel_query sends a query cancellation signal (SIGINT) to the backend process identified by query_id. The query_id of an active backend process can be found in the query_id column of the pg_stat_activity view.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SELECT query_id FROM pgxc_stat_activity WHERE stmt_type ='RESET';
 query_id
----------
        0
        0
(2 rows)

SELECT pg_cancel_query(0);
 pg_cancel_query
-----------------
 f
(1 row)

pg_terminate_query(queryId int)

Description: Terminates a current query of the backend. This function is supported in 8.1.2 or later.

Return type: Boolean.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SELECT query_id FROM pgxc_stat_activity WHERE stmt_type ='RESET';
 query_id
----------
        0
        0
(2 rows)

SELECT pg_terminate_query(0);
 pg_terminate_query
--------------------
 f
(1 row)