Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Correct way to kill a running query

First time running queries in rails console...

I had a query run accidentally: something like this

User.where(:location => 'US'))

which apparently is pulling me quite amount of data.

Now the query is still hanging there. I know I could just close this session and restart another. But I just would like to know the safest way to kill a query. Is there something similar like in mysql :

show full processlist 

and

 kill #
like image 916
peipei Avatar asked Jul 25 '14 17:07

peipei


1 Answers

When I want to stop a long running query, I typically just go up the chain of interrupts.

ctrl c will send SIGINT and hopefully just take you out of the current query or loop in the console. But, sometimes, this won't work so I go up a step to

ctrl \ which will send SIGQUIT to quit the current process. This command will exit out of the rails console and back in to the terminal (assuming you launched the console from rails c)

As a worst case scenario I will go to use ctrl z which will suspend the process allowing you to find the process ID (using top or ps or whatever else) and then use kill on that pid. If that doesn't work the final thing to use is kill -9 which will kill the process.

like image 129
jkeuhlen Avatar answered Oct 13 '22 06:10

jkeuhlen