How to postgresql find and kill a hanging query
1)
Login as superuser
$ sudo -u postgres psql
2)
Find "procpid" of your problematic query by running
postgres=# select * from pg_stat_activity;
3)
Kill your problematic query
postgres=# select pg_terminate_backend(procpid);
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.