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.