MongoDB log rotations can cause crashes


By David Mytton,
CEO & Founder of Server Density.

Published on the 7th January, 2013.

Logging is great for debugging but you have to deal with periodically rotating the files so they don’t become massive. We pipe all our logs into Papertrail so we can search them, doing log rotations every 12 hours for most things.

The ability for MongoDB to log to syslog was added in the 2.2 release so you can allow your system to deal with this. We log to a separate file and use a cron job to rotate the logs instead. The documentation recommends you do this by sending a SIGUSR1 flag to the Unix process. Doing this can cause the Mongo process to hang or crash.

Until this bug is fixed, you should use the mongo console to run the logRotate command:

mongo admin --eval "printjson(db.runCommand(\"logRotate\"))" --port 27017

This has the same effect but will avoid the crashing bug. It applies to both mongod and mongos.

Articles you care about. Delivered.

Help us speak your language. What is your primary tech stack?

Maybe another time