简体   繁体   English

用--nojournal选项启动mongod会删除现有的日志文件吗?

[英]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. 我的MongoDB因尝试附加到日志文件时发生的内存不足错误而崩溃。 At that instance, my mongod.lock file was empty. 在那种情况下,我的mongod.lock文件为空。 I restarted mongod without any options. 我重新启动了mongod,没有任何选择。 It was accepting connections normally. 它正常地接受连接。 Then I ran mongo.exe, but was unable to connect to db. 然后我运行mongo.exe,但无法连接到数据库。 It got stuck to "connecting to test" but never connected successfully. 它陷入了“连接测试”的困境,但从未成功连接。

I ended that process and I restarted mongod with --nojournal option. 我结束了该过程,并使用--nojournal选项重新启动了mongod。 But that didnt help either. 但这也没有帮助。

But now I see mongod.lock file non empty. 但是现在我看到mongod.lock文件不为空。 Also,all my journal entries are deleted. 另外,我的所有日​​记帐分录都被删除了。

The question is, does --noJournal option deletes existing journal entries? 问题是,--noJournal选项是否删除现有日记帐分录? Also, is there a way to recover the journal entries? 另外,有没有办法恢复日记帐分录?

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; 如果是独立实例,请使用--repair选项运行mongod
  • 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 --nojournal选项

Running mongod --nojournal will not remove journal files. 运行mongod --nojournal 不会删除日志文件。 In fact, mongod will not even start if there are journal files present. 实际上,如果存在日志文件, mongod甚至不会启动。 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. 如果随后运行不带--nojournal选项的mongod ,它将应用保存在日志文件中的所有更改并删除这些文件。 Only then can you restart it with --nojournal . 只有这样,您才能使用--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. 您无需尝试还原日志文件,因为它们已经应用于数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM