In the production environment, we strongly recommend that you enable journal. However, in some cases, you may want to disable it. Journal affects the writing speed of mongodb, even if there is no j option. If you can tolerate data loss or focus more on speed, disable journal. Disabling journal logging has a problem. After mongodb crashes, data integrity cannot be achieved.
In the production environment, we strongly recommend that you enable journal. However, in some cases, you may want to disable it. Journal affects the writing speed of mongodb, even if there is no j option. If you can tolerate data loss or focus more on speed, disable journal. Disabling journal logging has a problem. After mongodb crashes, data integrity cannot be achieved.
In the production environment, we strongly recommend that you enable journal. However, in some cases, you may want to disable it. Journal affects the writing speed of mongodb, even if there is no j option. If you can tolerate data loss or focus more on speed, disable journal. Disabling journal logging has a problem. The data integrity cannot be guaranteed after mongodb crashes. Without journal crash, data may be damaged and must be repaired or replaced. It is also possible that the data of this server cannot be used, or the work suddenly stops during use, and some data is damaged and lost. If you want to continue working normally after the crash, you can do the following: 1. Replace the data file. This is the best option. Delete all data directory files, recover from backup, create a snapshot from a clean member, or re-copy from the replica set to get a new copy of data. If there is a replica set with a small amount of data, it may be the best option to start a new copy, stop this set, delete the data directory file, and restart replication. 2. If the data file is not backed up, there is no copy, there is no replica set, and everything is done to remedy the data, the data can be recovered as much as possible. Therefore, you must back up data and ensure that the backup data is available. In this case, you need to use the repair command to delete any corrupted data. Mongod comes with two repair tools: Embedded mongod and embedded mongodump. Mongodump repair may find more data, but it takes a long time. In addition, if you use mongodump for restoration, you still need to restore the data before the restart. Therefore, it is acceptable to determine how long data can be restored. Run mongod with the -- repair Option: # mongod -- dbpath/path/to/mongoupt/data -- repair. When it is running in the repair status, mongodb cannot start listening port 27017, but you can view the log to see what you are doing. Note: The repair process requires a large amount of disk space to ensure that the available disk space exceeds the data size. For example, 80 GB of data requires 80 GB of available space. If the current disk space is insufficient, you can use the -- repairpath option to specify a new disk to be mounted. # Mongod -- dbpath/path/to/mongoupt/data ?? -- Repair -- repairpath/media/external-hd/data/db will not be affected if it is terminated by killed or insufficient disk space during the repair process. Because, all the repaired output is written to the new file, and the original file is not changed until the last moment. Mongodump use repair options :#? Mongodump -- repair3 .? Mongodb data directory contains a special file named mongod. lock. It is important to disable journal when running. When mongod is disabled normally, the mongod. lock file will be cleared and it will be known that it was completely closed the next time it was started. Conversely, if the lock file is not cleared, mongod is not properly disabled. If mongod detects that it is not properly disabled, it will not let you start again. You need to copy a copy of the data. However, some people have realized that they can bypass this check by deleting the lock file. However, do not do anything. Deleting the lock file at startup means you do not know or care whether your data is damaged. Unless this is the case, please respect the lock file. If you are prevented from starting mongod, fix your data instead of deleting the lock file. 4. An important reason not to delete the locked file during abnormal shutdown is that you may not even notice the hard disk crash. If you restart the server, the initialization script stops mongod before the server is shut down. However, initialization will attempt to gracefully shut down the process. If you do not close the process, it will be killed. In a busy system, mongodb may take a longer time to shut down. The init script will not wait for it to shut down, and it will be hard to shut down.
Original article address: mongodb persistence (2), thanks to the original author for sharing.