Check out example codes for "postgres kill running query". It will help you in understanding the concepts better.

Code Example 1

--Stop the query normally
SELECT pg_cancel_backend(pid);

--Terminate immediately
SELECT pg_terminate_backend(pid);

Learn ReactJs, React Native from akashmittal.com