Can I delete the mongodb log file?

If I delete the 3.1G log file, sudo service mongodb restart will fail. However, this file takes up too much space. How can I solve this problem? How to remove it?

 bash$ du -sh /var/lib/mongodb/* 4.0K _tmp 65M auction_development.0 128M auction_development.1 17M auction_development.ns 3.1G journal 4.0K mongod.lock 
+53
linux mongodb disk
Oct 23 '13 at 4:49 on
source share
3 answers

TL; DR: You have two options. Use the --smallfiles startup --smallfiles when starting MongoDB to limit the size of the log files to 128 MB or disable logging using the --nojournal . Using --nojournal in production is usually a bad idea, and it often makes sense to use different problems with writing and in development, so you don't have other code in dev and prod.

Long answer : No, deleting the log file is unsafe. The idea of ​​logging is this:

The record is included. Now, to make the recording permanent (and a solid database), the recording must somehow go to disk.

Unfortunately, writing to disk takes eons compared to writing to RAM , so there is a dilemma in the database: not writing to disk is risky because an unexpected shutdown will result in data loss. But writing to disk for each individual write operation reduces the database performance so much that it becomes unsuitable for practical purposes.

Now, instead of writing the data files themselves and instead doing this for each request, the database is simply added to the log file, where it saves all operations that have not yet been linked to the actual data files. This is much faster because the file is already "hot", because it is read and written all the time, and this is only one file, not a bunch of files, and finally, because it writes all pending operations in a batch every 100 ms by default . Deleting this file in the middle of something is damaging.

+58
Oct 23 '13 at 7:29
source share
β€” -

As explained in the mnemosin answer, logging is important for storage engines. Fortunately, it can be controlled to some extent. The following was written for the MMAPv1 storage engine : this is the default value before MongoDB 3.2. Then WiredTiger became the engine of choice, for which more information can be found at the bottom of this answer.

MMAPv1

MongoDB <2.6 (Non-YAML configuration)

For our development server, we used the following procedure:

 cp -p /etc/mongodb.conf /etc/mongodb.conf.orig vi /etc/mongodb.conf 

Now insert

 smallfiles=true 

in mongodb.conf, then save. smallfiles limits the log file to 128 MB.

 service mongodb stop rm -rf /var/lib/mongodb/journal/* service mongodb start 

MongoDB> = 2.6 (YAML configuration)

If you use MMAPv1 with the YAML configuration style , use the same step to back up the configuration as above, but in

  mmapv1: 

configuration block, insert

  smallFiles: true 

. Subsequently, proceed as described above, restart the server by deleting the logs.

WiredTiger (MongoDB> = 3.0, defaults to 3.2)

On development machines, the log files in WiredTiger are slightly smaller by default than in MMAPv1, because log compression is enabled by default. According to the documentation , "WiredTiger log files for MongoDB have a maximum size of approximately 100 MB." It will "create breakpoints (i.e., write snapshot data to disk) at intervals of 60 seconds or 2 gigabytes of log data."

Thus, if you use only a small number of queries (with a small amount of data to modify) in your database, the log files using WiredTiger should not exceed a minimum of 100 MB. However, the size of the log files is not configurable.

+63
Aug 26 '14 at 23:48
source share

mongodb evolved since then. Now its v3.4.1 stable .
I am here v3.2 here:
uncomment # mmapv1: so it looks like this:

  mmapv1: smallFiles: true 

if you have a different version, find storage Options on the reference/configuration-options page.

don't forget to let journal

 sudo service mongodb stop sudo rm -rf /var/lib/mongodb/journal/* sudo service mongodb start 
+3
Jan 22 '17 at 21:06 on
source share



All Articles