'kill a process dynamically in PostgreSQL

I want to kill a process dynamically in PostgreSQL. How it can be achieved?

I know it can be done manually using SELECT pg_terminate_backend(pid);



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source