I have a Replica Set with 3 MongoDB installed in Windows 2012 Server by using a configuration file through Windows Services.

Here is my mongod.cfg

       dbPath: E:\MongoDB\data
            enabled: true
      destination: file
      path: E:\MongoDB\log\mongod.log
      logRotate: rename
      logAppend: false
      timeStampFormat: iso8601-local

From my understanding, by setting logRotate to rename and logAppend to false this should happen automatically. For my surprise it does not!

Accordingly to MongoDB manual

MongoDB only rotates logs in response to the logRotate command, or when the mongod or mongos process receives a SIGUSR1 signal from the operating system.

After some digging, I found this ticket opened where it says that I should use a 3rd party tool to achieve it on Windows systems.

Is it the only way to rotate the logs on regular basis? And how would work in a Replica Set scenario?

  • I don't know windows, but I guess that it's same than in Unix. In Unix, you move the file first to new name and then you give SIGUSR1 to mongod process (or mongos). That makes that, process closes logfile handle and opens new one. In Unix you need to use "external" log rotate program too. – JJussi Sep 1 '17 at 21:43
  • What SIGUSR1 will do behind the scenes? And how can I do it in Windows? – Vinicius Deschamps Sep 3 '17 at 11:47
  • In Unix, even you move file to other name, as long as program have file handler open, it can keep writing to file. USR1-signal makes mongo{d/s} close-open that filehandler, so old file is freed and new file is created. I don't know how it is done in windows, but I guess that there is similar thing. – JJussi Sep 3 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.