1

Yesterday I moved 2 files from /var/log/mongodb to an other directory. The file names: "mongod.log", "mongod.log.1" (the only 2 files in this directory with large size). The mongodb was running at this point, I expected that mongodb creates a new mongod.log, but it did not do it. Then I created manually a mongod.log and made "chown mongodb:mongodb mongod.log", but the file is still empty.

I can not stop the mongodb, how can I force mongodb to log again in this file? The mongod.conf is fine.

jcomouth
  • 113
  • 1
  • 4

2 Answers2

2

That original file is still being held open by mongod despite the fact that you moved it, and it will continue to be the file it logs to until you stop the mongod process or try the following:

  1. Remove the new mongod.log file you created in /var/log/mongodb
  2. Move the old mongod.log file back in to /var/log/mongodb
  3. Issue the logRotate command from the mongo shell (when connected to the relevant mongod)

Note: Alternatively for step 3 you can send a kill -SIGUSR1 <pid of mongod> to achieve the same thing.

Once this is done, you will now have a new smaller mongod.log file in the folder, along with the truncated previous file (no longer being written to). The exact name depends on the version you are rinning which you have not mentioned but you are now free to move the large log files out to another directory (I would recommend compressing them, they are easily compressed).

If the size is a regular issue, I would recommend doing this as a cron job or similar to automate the process going forward.

Adam C
  • 2,745
1

Just issue the below command on runtime & you can see the logs being written to a specified log file:

db.adminCommand( { logRotate : 1 } )

Hope this helps !!!

Jerry
  • 651