Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill a process (query) in ClickHouse

Tags:

clickhouse

Is there any way to kill an idle query in ClickHouse? I have an OPTIMIZE query that will never be completed (as it is running against a ReplicatedMergeTree table) blocking a table that I need to delete.

like image 499
DamnWidget Avatar asked Nov 11 '16 11:11

DamnWidget


2 Answers

I usually run

SELECT query_id, query FROM system.processes;

To find running queries. From that list I find query_id of query I want to kill and then execute

KILL QUERY WHERE query_id = '<id>';

More info can be found in Documentation on KILL QUERY

To kill Mutation, there's similar KILL MUTATION.

like image 151
simPod Avatar answered Nov 05 '22 23:11

simPod


Yes, there is a replace_running_query option.

In short, you can add a query_id parameter to your HTTP request, like that:

http://localhost:8123/?query=SELECT * FROM system.numbers LIMIT 100000000& replace_running_query=1&query_id=example

Then do a second HTTP request, with the same query_id:

http://localhost:8123/?query=SELECT 1&replace_running_query=1&query_id=example

The server will cancel the first query and run the second one instead.

You can override the option (it is disabled by default) in your config file to get rid of placing it in the request arguments.

like image 5
Igor Hatarist Avatar answered Nov 06 '22 00:11

Igor Hatarist