In this article, we will see difference between pg_cancel_backend and pg_terminate_backend in PostgreSQL.
pg_cancel_backend(pid) is a milder version og pg_terminate_backend(pid).
The difference between pg_cancel_backend and pg_terminate_backend in PostgreSQL is that
pg_cancel_backend() just cancels the current query
pg_terminate_backend() really kills the backend(this can be used for idle or idle in transaction backends)
We can run either this function as a superuser or with the same as tha of the offending backend process.