1

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?

Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67
riteshkasat
  • 803
  • 10
  • 15

1 Answers1

1

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.

Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67
  • Dmytro Shevchenko, Your answer is very insightful. As per your answer, I just need to run mongod --repair because journal changes are already applied. But there is a small issue. My data size is around 50GB and the remaining free space in drive is around 20GB. I read online that, the repair option needs memory at-least as much as the existing data size plus additional 2 GB. Do you think, I should just run mongod --repair. Or I should extend my hard-drive capacity before trying the --repair option. PS, my MongoDB is running on Microsoft 2012 R2 server. Thanks! – riteshkasat Nov 05 '15 at 10:18
  • @riteshkasat OK, in that case, you shouldn't run repair until you have enough disk space. – Dmytro Shevchenko Nov 05 '15 at 10:58