How to kill a process in
If you are unfamiliar with your current database schema and indexes, or run a heavy query by mistake on production database things go nasty! To find the query and kill it run mongo client as below and run
to run
#mongodb #mongo #killOp #currentOp #query
mongo
shell?If you are unfamiliar with your current database schema and indexes, or run a heavy query by mistake on production database things go nasty! To find the query and kill it run mongo client as below and run
currentOp
command:> mongo
> db.currentOp()
currentOp()
database method will display the ongoing queries in json format, find the query which is related to you and get its opid
. Now you needto run
killOp()
database method to kill that process as below:db.killOp(229)
229
is the operation id we have got from the first command.NOTE:
terminate running operations with extreme caution. Only use db.killOp() to terminate operations initiated by clients and do not terminate internal database operations.#mongodb #mongo #killOp #currentOp #query
On previous posts we explained about query slowness. Here we try to explain different parts of the function.
can use command like
The part we are interested in is
This is all we've done in previous posts, to kill slow queries in mongoDB.
#mongodb #mongo #currentOp #killOp #opid
db.currentOp
: in progress operations in mongoDB is displayed by this command. The response of the command is in json format, so youcan use command like
db.currentOp()['inprog']
. The response has many useful informations like lock status
, numYields
and so on.The part we are interested in is
opid
part. opid
is the pid number of the query operation. op
section of each operation shows the type of the query. It can be an internal database command, insert command and or query. secs_running
of the operation is the part that we can check whether a query has taken a long time or not. It is in second.db.killOp
: killing an operation is just as simple as giving the opid
number to killOp
as below:db.killOp(6123213)
This is all we've done in previous posts, to kill slow queries in mongoDB.
#mongodb #mongo #currentOp #killOp #opid