riteshkasat
riteshkasat

Reputation: 803

Starting mongod with --nojournal option deletes existing journal files?

My MongoDB had crashed due to out of memory error that occurred when it tried appending to a journal file. At that instance, my mongod.lock file was empty. I restarted mongod without any options. It was accepting connections normally. Then I ran mongo.exe, but was unable to connect to db. It got stuck to "connecting to test" but never connected successfully.

I ended that process and I restarted mongod with --nojournal option. But that didnt help either.

But now I see mongod.lock file non empty. Also,all my journal entries are deleted.

The question is, does --noJournal option deletes existing journal entries? Also, is there a way to recover the journal entries?

Upvotes: 1

Views: 7611

Answers (1)

Dmytro Shevchenko
Dmytro Shevchenko

Reputation: 34581

Recovering after a crash

First, please read this article:

Recover Data after an Unexpected Shutdown

After a crash, you have two options:

  • if it is a standalone instance, run mongod with the --repair option;
  • if the instance is a part of a replica set, wipe all data and either restore from a backup or perform an initial sync from another replica set member.

The --nojournal option

Running mongod --nojournal will not remove journal files. In fact, mongod will not even start if there are journal files present. It will give you the following message and shut down.

Error: journal files are present in journal directory, yet starting without journaling enabled.
It is recommended that you start with journaling enabled so that recovery may occur.
exception in initAndListen: 13597 can't start without --journal enabled when journal/ files are present, terminating

If you then run mongod without the --nojournal option, it will apply all changes saved in journal files and remove the files. Only then can you restart it with --nojournal.

I believe this is what happened in your case. You don't need to attempt to restore your journal files, as they are already applied to your data.

Upvotes: 1

Related Questions