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, и N. Marchand. Proceedings of the European Control Conference 2009, стр. 1979-1984. Budapest, Hongrie, (августа 2009)Département Automatique Département Automatique.