To stop the query:
SELECT pg_cancel_backend(procpid);
To kill the database connection:
SELECT pg_terminate_backend(procpid);
To get an overview of the current transactions, to get the proced id’s:
SELECT * FROM pg_stat_activity;
http://www.postgresql.org/docs/current/interactive/functions-admin.html