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);
S. Durand, und N. Marchand. Proceedings of the European Control Conference 2009, Seite 1979-1984. Budapest, Hongrie, (August 2009)Département Automatique Département Automatique.
M. Streeter, M. Keane, und J. Koza. Preprints of the 2003 Intelligent Control Systems and
Signal Processing Conference, Seite 494--499. Faro, Portugal, (2003)