Postgres eating too much CPU?

Problems with PostgreSQL postmaster process eating too much CPU?

A query is out of control…

Detect the offending query by getting its process PID (eg. via the top command)

Postgres postmaster process hogging the CPU

Via the psql shell on the remote machine, get the problematic SQL code:

 $ sudo su - postgres
 $ psql

psql (9.3.3)
Type "help" for help.

postgres=# SELECT current_query from pg_stat_activity where procpid = 6388;

  select count(distinct as col_0_0_ from Task taskimpl0_ ...

postgres=# SELECT pg_cancel_backend(6388);

 $ kill -9 6388     # Optional step

Tip: how to list queries for a given user:

postgres=# SELECT procpid, usename FROM pg_stat_activity where usename = 'myuser';

 procpid | usename
    6388 | myuser
    6394 | myuser
(2 rows)