Repairing a MongoDB Database

There are a couple reasons to run a repair on the MongoDB database—for example, if the system crashes, or if a data integrity problem is manifested in the application, or even just to reclaim some unused disk space.

You can initiate a repair of a MongoDB database from the MongoDB shell or from the mongod command line. To execute a repair from the command line, use --repair and --repairpath <repair_path>. <repair_path> specifies the location to store temporary repair files. For example:

mongod --repair --repairpath /tmp/mongdb/data

To execute a repair from the MongoDB client, use the db.repairDatabase(options) command, as in this example:

db.repairDatabase({ repairDatabase: 1,
  preserveClonedFilesOnFailure: <boolean>,
  backupOriginalFiles: <boolean> })

When a repair is initiated, all collections in the database are compacted, which reduces the size on disk. Also, any invalid records in the database are deleted. Therefore, it may be better to restore from backup than to run a repair.

The time it takes to run a repair depends on the size of the data. Repairs impact the performance of systems and should be run during off-peak hours.


Warning

If you are trying to repair a member of a replica set and you have access to an intact copy of your data on another replica, you should restore from that intact copy because repairDatabase will delete the corrupt data, and it will be lost.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.131.152.166