Suppose there is an AQL query that’s executing in the server for a long time already and you want to get rid of it. What can be done to abort that query?
If a connection to the server can still be established, the easiest is to use the ArangoShell to fetch the list of currently executing AQL queries and send a kill command to the server for the correct query.
To start, we can fetch the list of all running queries and print their ids, query strings and runtimes. This is only inspection and does not abort any query:
1 2 |
|
Here’s an example result for the list of running queries:
1 2 3 4 5 6 7 8 |
|
To now kill a query from the list, we can pass the query’s id to kill:
1 2 |
|
If a query was actually killed on the server, that call should return without an error, and the server should have logged a warning in addition.
If we wanted to abort one or many queries from the list solely by looking at query string patterns or query runtime, we could iterate over the list of current queries and kill each one that matches a predicate.
For example, the following snippet will abort all currently running
queries that contain the string SLEEP
anywhere inside their query string:
1 2 3 4 5 6 7 8 |
|
Filtering based on current query runtime is also simple, by adjusting the predicate. To abort all queries that ran longer than 30 seconds use:
1 2 3 4 5 6 7 8 |
|
Please make sure the predicates are correct so only the actually intended queries get aborted!
To test a predicate without killing a query, use the above code without the
forEach
part that did the killing.