MongoDB database repair

Source: Internet
Author: User

View the MongoDB. log and find the following statements in the log:
..............
Mon Mar 317: 46: 37 [conn148] assertion: 10295:GetFile (): Bad file number value (upt DB ?) : Run repair

..............

Or

Com. MongoDB. mongoexception: Bad offset: 0 accessing File:/data/dbdata/db.0-consider repairing Database


Declaration: GetFile (): incorrect file value (corrupt database ?) : Run repair

Check the MongoDB document and use the following methods to fix the problem:

First, stop the mongod service, delete MongoDB. log, and back up it.
# Rm-RF/data/MongoDB. Log

Delete MongoDB process files
# Rm-RF/MongoDB/mongod. Lock

Repair

#/Usr/local/MongoDB/bin/mongod -- repair -- dbpath/MongoDB/-- repairpath/MongoDB/repair/

If

./Mongod -- repair -- dbpath/data/dbdata -- repairpath/data/repair/-- logpath/data/dblog/mongodbrepair. log -- fork


At this time, the MongoDB process will store temporary repair database files in the/MongoDB/repair/directory. The file directory is "$ tmp_repairdatabase_0", so the directory space should be large enough.
The database in the production environment is 100 GB, and the repair takes about three and a half hours. A temporary database file of nearly 30 GB is generated in the "/MongoDB/repair/$ tmp_repairdatabase_0" directory, after the repair is completed, the temporary database files are automatically cleared.

Then enable the mongod service, check the database, and find that the read and write operations are normal. There is no error in MongoDB. log. Fix OK!

The principle is: Read the data again and write it to another database.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.