7

I have a mongodb database that uses approximately 1GB of space. I was surprised when my server ran out of space, and then I realized that the journal uses 3GB.

The documentation says that "Once MongoDB applies all the write operations in the journal files, it deletes these files", but that does not seems to be the case, since the database is synced and journaling is 3 times bigger than whole database.

How can I have those journaling files deleted and configure the system to use less space?

  • Have you tried a clean shutdown? That same link says it will clear the journal. – user3463 Oct 10 '13 at 22:10
  • I restarted the server, which I assume is a clean shutdown, but the journal files remained there... – lfagundes Oct 11 '13 at 0:34
  • How often do you write data to your database? To reduce journal file size you must use smallfiles option when starting mongod, that's what documentation recommends: docs.mongodb.org/manual/reference/configuration-options/… But it has its drawbacks because it creates many files. – Binarysurf Oct 11 '13 at 0:48
3

The documentation you quote is correct, if you run the db.fsyncLock() command you will flush all changes to disk and the journal files will be deleted. As soon as you run db.fsyncUnlock() and another write arrives, those journal files will reappear:

Here's a quick example on a test system:

> db.foo.insert({"id" : 1})

Here's what the journal directory looks like:

$ls /usr/local/var/mongodb/journal/
j._1 lsn
$

Now, let's lock it up and flush everything to disk:

> db.fsyncLock()
{
    "info" : "now locked against writes, use db.fsyncUnlock() to unlock",
    "seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
    "ok" : 1
}

The journal directory is now empty:

$ls /usr/local/var/mongodb/journal/
$

Unlock, insert:

> db.fsyncUnlock()
{ "ok" : 1, "info" : "unlock completed" }
> db.foo.insert({"id" : 1})

Now we have journal files again:

$ls /usr/local/var/mongodb/journal/
j._2 lsn
$

Hence, if you are not locking, flushing the databases to disk and constantly have writes coming in you will always have journal files.

Similarly, when you shut down a mongod instance cleanly, the journal files will be deleted once the flush to disk has completed successfully.

If you would like to make the journal files smaller, you can look into running with the --smallfiles option. This will give you 3 x 128MB files rather than 3 x 1GB files.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.