17

What's the difference between functions: pg_cancel_backend(pid int) and pg_terminate_backend(pid int)? For me they work pretty the same.

Borys
  • 2,676
  • 2
  • 24
  • 37

1 Answers1

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
  • 7
    that 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