Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to recover mongodb after unexpected shutdown?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 930
    Comment on it

    There might be a situation when one cannot start the MongoDB due to unexpected shutdown or mongo server crashing.

    This is because of the mongod.lock file which is preventing to start mongoDb server.

     

    Below are the steps to recover MongoDB:

     

    Step 1-

    Deleting the mongod.lock file

     

    You can either delete the mongod.lock file manually under the respective directory or by below step from terminal:

    sudo rm /var/lib/mongodb/mongod.lock

     

    Step 2-

    Repairing MongoDb using mongod --repair

    ankitchettri@ankitchettri:~$ mongod --repair
    Thu Apr 20 11:03:05
    Thu Apr 20 11:03:05 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
    Thu Apr 20 11:03:05
    Thu Apr 20 11:03:05 [initandlisten] MongoDB starting : pid=5012 port=27017 dbpath=/data/db/ 32-bit host=ankitchettri
    Thu Apr 20 11:03:05 [initandlisten]
    Thu Apr 20 11:03:05 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
    Thu Apr 20 11:03:05 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
        Thu Apr 20 11:03:05 [initandlisten] **       with --journal, the limit is lower
    Thu Apr 20 11:03:05 [initandlisten]
    Thu Apr 20 11:03:05 [initandlisten] db version v2.0.4, pdfile version 4.5
    Thu Apr 20 11:03:05 [initandlisten] git version: nogitversion
    Thu Apr 20 11:03:05 [initandlisten] build info: Linux roseapple 2.6.42-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 i686 BOOST_LIB_VERSION=1_46_1
    Thu Apr 20 11:03:05 [initandlisten] options: { repair: true }
    Thu Apr 20 11:03:05 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
    Thu Apr 20 11:03:05 dbexit:
    Thu Apr 20 11:03:05 [initandlisten] shutdown: going to close listening sockets...
    Thu Apr 20 11:03:05 [initandlisten] shutdown: going to flush diaglog...
    Thu Apr 20 11:03:05 [initandlisten] shutdown: going to close sockets...
    Thu Apr 20 11:03:05 [initandlisten] shutdown: waiting for fs preallocator...
    Thu Apr 20 11:03:05 [initandlisten] shutdown: closing all files...
    Thu Apr 20 11:03:05 [initandlisten] closeAllFiles() finished

     

    Step 3-

    Starting MongoDb server

    sudo service mongodb start

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: