What's the difference between functions: pg_cancel_backend(pid int) and pg_terminate_backend(pid int)? For me they work pretty the same.
Asked
Active
Viewed 1.0k times
17
-
Isn't this about the difference between a clean shutdown vs an sloppy one `(kill -9)`? – Denis de Bernardy Sep 18 '13 at 08:46
1 Answers
30
pg_cancel_backend() cancels the running query while pg_terminate_backend() terminates the entire process and thus the database connection.
When a program creates a database connection and sends queries, you can cancel one query without destroying the connection and stopping the other queries. If you destroy the entire connection, everything will be stopped.

Frank Heikens
- 117,544
- 24
- 142
- 135
-
Is there a reference to official documentation about the behavior of the two signals? I couldn't find any myself. – chutz Jun 19 '15 at 03:26
-
@chutz: See http://www.postgresql.org/docs/current/interactive/functions-admin.html – Frank Heikens Jun 19 '15 at 07:40
-
7that document only mentions that these two funcitons send signals to the backend, but they do not explain what the signals do. There is documentation about sending signals to the master process, but not to individual backends. – chutz Jun 19 '15 at 07:47