SELECT * FROM pg_stat_activity WHERE state = 'active';
So you can identify the PID of the hanging query you want to terminate, run this:
SELECT pg_cancel_backend(PID);
G. Stumme. Conceptual Structures at Work: 12th International Conference on Conceptual Structures (ICCS 2004), volume 3127 of LNCS, page 109-125. Heidelberg, Springer, (2004)
J. Cugini. Information Doors -- Where Information Search and Hypertext Link workshop (held in conjunction with the ACM Hypertext and Digital Libraries conferences)., San Antonio, Texas, (2000)
J. Cugini, S. Laskowski, and M. Sebrechts. IST/SPIE's 12th Annual International Symposium: Electronic Imaging 2000: Visual Data Exploration and Analysis (SPIE 2000), San Jose, CA, (2000)
B. Fonseca, P. Golgher, B. Pôssas, B. Ribeiro-Neto, and N. Ziviani. CIKM '05: Proceedings of the 14th ACM international conference on Information and knowledge management, page 696--703. New York, NY, USA, ACM Press, (2005)