We can terminate the PostgreSQL query by terminating the corresponding process id.
Step1: Login to PostgreSQL shell as admin user.
Step2: List out the processes that are running currently and note down the process id that we need to stop.
>SELECT * FROM pg_stat_activity;
Step3: Terminate the required process id.
Here we need to replace PID with the corresponding process id.