Manage Journaling
MongoDB uses write ahead logging to an on-disk journal toguarantee write operation durability.
The WiredTiger storage engine does not require journaling to guaranteea consistent state after a crash. The database will be restored to thelast consistent checkpointduring recovery. However, if MongoDB exits unexpectedly in betweencheckpoints, journaling is required to recover writes that occurredafter the last checkpoint.
Note
Starting in MongoDB 4.0, you cannot specify —nojournal
option or storage.journal.enabled:false
for replica set members that use theWiredTiger storage engine.
With journaling enabled, if mongod
stops unexpectedly, theprogram can recover everything written to the journal. MongoDB willre-apply the write operations on restart and maintain a consistentstate. By default, the greatest extent of lost writes, i.e., those notmade to the journal, are those made in the last 100 milliseconds, plusthe time it takes to perform the actual journal writes. SeecommitIntervalMs
for more information onthe default.
Procedures
Disable Journaling
Warning
Do not disable journaling on production systems.
- Starting in MongoDB 4.0, you cannot specify
—nojournal
option orstorage.journal.enabled:false
for replica set members that use theWiredTiger storage engine.
To disable journaling for a standalone deployment, startmongod
with the —nojournal
command line option.
Get Commit Acknowledgement
You can get commit acknowledgement with the Write Concern andthe j
option. For details, seeWrite Concern.
Monitor Journal Status
The serverStatus
command/db.serverStatus()
method returns wiredTiger.log
, which containsstatistics on the journal.
Recover Data After Unexpected Shutdown
On a restart after a crash, MongoDB replays all journal files in thejournal directory before the server becomes available. If MongoDB mustreplay journal files, mongod
notes these events in the logoutput.
There is no reason to run —repair
.
Change WiredTiger Journal Compressor
With the WiredTiger storage engine, MongoDB, by default, uses thesnappy
compressor for the journal. To specify a differentcompressions algorithm or no compression for a mongod
instance:
Tip
If you encounter an unclean shutdown for a mongod
during this procedure, you must use the old compressor settings torecover using the journal files. Once recovered, you can retry theprocedure.
- Standalone
- Replica Set Member
- Sharded Cluster Member
Use the following procedure to change the journal compressorfor a standalone mongod
instance:
- Update the
storage.wiredTiger.engineConfig.journalCompressor
settingto the new value.
If you use command-line options instead of a configuration file, youwill have to update the —wiredTigerJournalCompressor
command-line option duringthe restart below.
- Perform a clean shutdown of the
mongod
instance. For example, connect amongo
shell to the instance and issuedb.shutdownServer()
:
- db.getSiblingDB('admin').shutdownServer()
Once you have confirmed that the process is no longer running,restart the
mongod
instance:- If you are using a configuration file:
- mongod -f <path/to/myconfig.conf>
- If you are using command-line options instead of a configurationfile, update the
—wiredTigerJournalCompressor
option.
- mongod --wiredTigerJournalCompressor <differentCompressor|none> ...
Use the following procedure to change the journal compressorfor a member of a replica set:
Note
The following procedure involves restarting the replica member as astandalone without the journal.
- Perform a clean shutdown of the
mongod
instance. For example, connect amongo
shell to the instance and issuedb.shutdownServer()
:
- db.getSiblingDB('admin').shutdownServer()
Update the configuration file to prepare to restart as astandalone:
- Set
storage.journal.enabled
tofalse
. - Comment out the replication settingsfor your deployment.
- Set parameter
disableLogicalSessionCacheRefresh
totrue
in thesetParameter
section.For example:
- Set
- storage:
- journal:
- enabled: false
- #replication:
- # replSetName: replA
- setParameter:
- disableLogicalSessionCacheRefresh: true
If you use command-line options instead of a configuration file, youwill have to update the command-line option during the restart.
Restart the
mongod
instance:- If you are using a configuration file:
- mongod -f <path/to/myconfig.conf>
If you are using command-line options instead of aconfiguration file,
Include the
—nojournal
optionRemove any replication command-line options (such as
—replSet
):Set parameter
disableLogicalSessionCacheRefresh
totrue
in the—setParameter
option.
- mongod --nojournal --setParameter disableLogicalSessionCacheRefresh=true ...
- Perform a clean shutdown of the
mongod
instance:
- db.getSiblingDB('admin').shutdownServer()
Confirm that the process is no longer running.
Update the configuration file to prepare to restart as a replica setmember with the new journal compressor:
- Remove the
storage.journal.enabled
setting. - Uncomment the replicationsettings for your deployment.
- Remove the
disableLogicalSessionCacheRefresh
parameter. - Remove
storage.wiredTiger.engineConfig.journalCompressor
settingto use the default journal compressor or specify a new value.For example:
- Remove the
- storage:
- wiredTiger:
- engineConfig:
- journalCompressor: <newValue>
- replication:
- replSetName: replA
If you use command-line options instead of a configuration file, youwill have to update the command-line options during the restartbelow.
Restart the
mongod
instance as a replica set member:- If you are using a configuration file:
- mongod -f <path/to/myconfig.conf>
If you are using command-line options instead of a configurationfile:
- Remove the
—nojournal
option. - Remove the
—wiredTigerJournalCompressor
command-line option to usethe default journal compressor or update to a new value. - Include your replication command-line options as well as any additionaloptions for your replica set member.
- Remove the
disableLogicalSessionCacheRefresh
parameter.
- Remove the
- mongod --wiredTigerJournalCompressor <differentCompressor|none> --replSet ...
Use the following procedure to change the journal compressorfor a member of a shard replica set or config server replica set:
Note
The following procedure involves restarting the replica member as astandalone without the journal.
- Perform a clean shutdown of the
mongod
instance. For example, connect amongo
shell to the instance and issuedb.shutdownServer()
:
- db.getSiblingDB('admin').shutdownServer()
Update the configuration file to prepare to restart as astandalone:
- Set
storage.journal.enabled
tofalse
. - Set parameter
skipShardingConfigurationChecks
to true. - Set parameter
disableLogicalSessionCacheRefresh
totrue
in thesetParameter
section. - Comment out the replicationsettings for your deployment.
- Comment out the
sharding.clusterRole
setting. - Set the
net.port
to the member’scurrent port, if it is not explicitly set.For example:
- Set
- storage:
- journal:
- enabled: false
- setParameter:
- skipShardingConfigurationChecks: true
- disableLogicalSessionCacheRefresh: true
- #replication:
- # replSetName: shardA
- #sharding:
- # clusterRole: shardsvr
- net:
- port: 27218
If you use command-line options instead of a configuration file, youwill have to update the command-line option during the restart.
Restart the
mongod
instance:- If you are using a configuration file:
- mongod -f <path/to/myconfig.conf>
If you are using command-line options instead of aconfiguration file:
- Include the
—nojournal
option. - Set parameter
skipShardingConfigurationChecks
to true. - Set parameter
disableLogicalSessionCacheRefresh
totrue
in the—setParameter
option. - Remove any replication command-line options (such as
—replSet
). - Remove
—shardsvr
/—configsvr
option. - Explicitly include
—port
set tothe instance’s current port.
- Include the
- mongod --nojournal --setParameter skipShardingConfigurationChecks=true --setParameter disableLogicalSessionCacheRefresh=true --port <samePort> ...
- Perform a clean shutdown of the
mongod
instance:
- db.getSiblingDB('admin').shutdownServer()
Confirm that the process is no longer running.
Update the configuration file to prepare to restart with the new journal compressor:
- Remove the
storage.journal.enabled
setting. - Remove the
skipShardingConfigurationChecks
parameter setting. - Remove the
disableLogicalSessionCacheRefresh
parameter setting. - Uncomment the replicationsettings for your deployment.
- Uncomment the
sharding.clusterRole
setting. - Remove
storage.wiredTiger.engineConfig.journalCompressor
settingto use the default journal compressor or specify a new value.For example:
- Remove the
- storage:
- wiredTiger:
- engineConfig:
- journalCompressor: <newValue>
- replication:
- replSetName: shardA
- sharding:
- clusterRole: shardsvr
- net:
- port: 27218
If you use command-line options instead of a configuration file, youwill have to update the command-line options during the restartbelow.
Restart the
mongod
instance as a replica set member:- If you are using a configuration file:
- mongod -f <path/to/myconfig.conf>
If you are using command-line options instead of a configurationfile:
- Remove the
—nojournal
option. - Remove the
skipShardingConfigurationChecks
parameter setting. - Remove the
disableLogicalSessionCacheRefresh
parameter. - Remove the
—wiredTigerJournalCompressor
command-line option to usethe default journal compressor or update to a new value. - Include
—shardsvr
/—configsvr
option. - Include your replication command-line options as well as any additionaloptions for your replica set member.
- Remove the
- mongod --shardsvr --wiredTigerJournalCompressor <differentCompressor|none> --replSet ...