Created
August 22, 2018 06:45
-
-
Save arzzen/6a881e92ec43a56f4d33ef0a0d49e722 to your computer and use it in GitHub Desktop.
Find and (safely) kill long running MongoDB queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var maxSecsRunning = 600; | |
var dryRun = true; | |
var currOp = db.currentOp(); | |
for (var oper in currOp.inprog) { | |
var op = currOp.inprog[oper-0]; | |
if (op.secs_running > maxSecsRunning && op.op == "command" ) { | |
print("Killing opId: " + op.opid | |
+ " running for over secs: " | |
+ op.secs_running | |
); | |
if(!dryRun) { | |
db.killOp(op.opid); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment