Manage Journaling管理日记
On this page本页内容
MongoDB uses write ahead logging to an on-disk journal to guarantee write operation durability.MongoDB使用写前日志记录到磁盘上的日志,以保证写操作的持久性。
The WiredTiger storage engine does not require journaling to guarantee a consistent state after a crash. WiredTiger存储引擎不需要日志记录来保证崩溃后的一致状态。The database will be restored to the last consistent checkpoint during recovery. 数据库将在恢复过程中恢复到最后一个一致性检查点。However, if MongoDB exits unexpectedly in between checkpoints, journaling is required to recover writes that occurred after the last checkpoint.但是,如果MongoDB在检查点之间意外退出,则需要日志记录来恢复上次检查点之后发生的写入。
If 如果mongod
stops unexpectedly, the program can recover everything written to the journal. mongod
意外停止,程序可以恢复写入日志的所有内容。MongoDB will re-apply the write operations on restart and maintain a consistent state. MongoDB将在重新启动时重新应用写入操作,并保持一致的状态。By default, the greatest extent of lost writes, i.e., those not made to the journal, are those made in the last 100 milliseconds, plus the time it takes to perform the actual journal writes. 默认情况下,最大程度的丢失写入,即未写入日志的写入,是在最近100毫秒内完成的写入,加上执行实际日志写入所需的时间。See 有关默认值的详细信息,请参阅commitIntervalMs
for more information on the default.commitIntervalMs
。
Procedures过程
Get Commit Acknowledgement获取提交确认
You can get commit acknowledgement with the Write Concern and the 您可以通过写入关注和j
option. j
选项获得提交确认。For details, see Write Concern.有关详细信息,请参阅写入关注。
Monitor Journal Status监视日志状态
The serverStatus
command/db.serverStatus()
method returns wiredTiger.log
, which contains statistics on the journal.serverStatus
命令/db.serverStatus()
方法返回wiredTigerlog,其中包含日志的统计信息。
Recover Data After Unexpected Shutdown意外关闭后恢复数据
On a restart after a crash, MongoDB replays all journal files in the journal directory before the server becomes available. If MongoDB must replay journal files, 在崩溃后重新启动时,MongoDB会在服务器可用之前重播日志目录中的所有日志文件。如果MongoDB必须重放日志文件,mongod
notes these events in the log output.mongod
会在日志输出中记录这些事件。
There is no reason to run 没有理由运行--repair
.--repair
。
Change WiredTiger Journal Compressor更换WiredTiger日志压缩器
With the WiredTiger storage engine, MongoDB, by default, uses the 在WiredTiger存储引擎中,MongoDB默认情况下会为日志使用snappy
compressor for the journal. snappy
压缩器。To specify a different compressions algorithm or no compression for a 要为mongod
instance:mongod
实例指定不同的压缩算法或不指定压缩,请执行以下操作:
If you encounter an unclean shutdown for a 如果在此过程中遇到mongod
during this procedure, you must use the old compressor settings to recover using the journal files. Once recovered, you can retry the procedure.mongod
的不干净关闭,则必须使用旧的压缩器设置使用日志文件进行恢复。恢复后,您可以重试该过程。
Use the following procedure to change the journal compressor for a standalone 使用以下过程更改独立mongod
instance:mongod
实例的日志压缩器:
-
Update将storage.wiredTiger.engineConfig.journalCompressor
to the new value.storage.wiredTiger.engineConfig.journalCompressor
更新为新值。If you use command-line options instead of a configuration file, you must update the如果使用命令行选项而不是配置文件,则必须在下面的重新启动过程中更新--wiredTigerJournalCompressor
command-line option during the restart below.--wiredTigerJournalCompressor
命令行选项。 -
Perform a clean shutdown of the执行mongod
instance.mongod
实例的干净关闭。For example, connect例如,将mongosh
to the instance and issuedb.shutdownServer()
:mongosh
连接到实例并发出db.shutdownServer()
:db.getSiblingDB('admin').shutdownServer()
-
Once you have confirmed that the process is no longer running, restart the一旦确认进程不再运行,请重新启动mongod
instance:mongod
实例:-
If you are using a configuration file:如果您正在使用配置文件:mongod -f <path/to/myconfig.conf>
-
If you are using command-line options instead of a configuration file, update如果使用命令行选项而不是配置文件,请将--wiredTigerJournalCompressor
to the new value.--wiredTigerJournalCompressor
更新为新值。mongod --wiredTigerJournalCompressor <differentCompressor|none> ...
-
Use the following procedure to change the journal compressor for a member of a replica set:使用以下过程可以更改复制集成员的日志压缩器:
-
Perform a clean shutdown of the执行mongod
instance.mongod
实例的干净关闭。For example, connect例如,将mongosh
to the instance and issuedb.shutdownServer()
:mongosh
连接到实例并发出db.shutdownServer()
:db.getSiblingDB('admin').shutdownServer()
-
Update将storage.wiredTiger.engineConfig.journalCompressor
to the new value.storage.wiredTiger.engineConfig.journalCompressor
更新为新值。If you use command-line options instead of a configuration file, you must update the command-line options during the restart below.如果使用命令行选项而不是配置文件,则必须在下面的重新启动过程中更新命令行选项。 -
Restart the重新启动mongod
instance:mongod
实例:-
If you are using a configuration file:如果您正在使用配置文件:mongod -f <path/to/myconfig.conf>
-
If you are using command-line options instead of a configuration file, update如果使用命令行选项而不是配置文件,请将--wiredTigerJournalCompressor
to the new value.--wiredTigerJournalCompressor
更新为新值。mongod --wiredTigerJournalCompressor <differentCompressor|none> ...
-
Use the following procedure to change the journal compressor for a member of a shard replica set or config server replica set:使用以下过程更改分片副本集或配置服务器副本集成员的日志压缩器:
-
Perform a clean shutdown of the执行mongod
instance. For example, connectmongosh
to the instance and issuedb.shutdownServer()
:mongod
实例的干净关闭。例如,将mongosh
连接到实例并发出db.shutdownServer()
:db.getSiblingDB('admin').shutdownServer()
-
Update将storage.wiredTiger.engineConfig.journalCompressor
to the new value.storage.wiredTiger.engineConfig.journalCompressor
更新为新值。If you use command-line options instead of a configuration file, you must update the command-line options during the restart below.如果使用命令行选项而不是配置文件,则必须在下面的重新启动过程中更新命令行选项。 -
Restart the重新启动mongod
instance:mongod
实例:-
If you are using a configuration file:如果您正在使用配置文件:mongod -f <path/to/myconfig.conf>
-
If you are using command-line options instead of a configuration file, update如果使用命令行选项而不是配置文件,请将--wiredTigerJournalCompressor
to the new value.--wiredTigerJournalCompressor
更新为新值。mongod --shardsvr --wiredTigerJournalCompressor <differentCompressor|none> --replSet ...
-