Skip to content

Instantly share code, notes, and snippets.

@arzzen
Created August 22, 2018 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arzzen/6a881e92ec43a56f4d33ef0a0d49e722 to your computer and use it in GitHub Desktop.
Save arzzen/6a881e92ec43a56f4d33ef0a0d49e722 to your computer and use it in GitHub Desktop.
Find and (safely) kill long running MongoDB queries
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