Hi Harry,
As you reported "pg_terminate_backend(pid)" returning "f" when executing. Please confirm are u getting any error like below .
postgres=# select pg_terminate_backend(342033);
WARNING: PID 342033 is not a PostgreSQL server process
pg_terminate_backend
----------------------
f
(1 row)
Not sure, what kind of error your are getting while executing it. So, requesting you to share your postgresql version, command what you have executed and it's result. However, pg_terminate_backend() is responsible to send "SIGTERM" to it's OS process. From there onwards, OS will take care about the given process termination.
Can you give a try, by picking the IP's of the processes which are not getting killed from pg_stat_activity(client_addr column) and make REJECT entries in pg_hba.conf file as below:
host all all <client_addr IP> reject
and reload the cluster using pg_ctl -D $PGDATA reload
Now try killing the process
pg_ctl kill TERM <Process PID>
I am not sure why we are rejecting the incoming connections here.
Regards,