old lock file: \data\db\mongod.lock, probably means unclean shutdown

When Staring the mongoDB server, it hits below errors, and the mongoDB server is unable to start.


**************
old lock file: \data\db\mongod.lock.  probably means unclean shutdown
recommend removing file and running --repair
see: http://dochub.mongodb.org/core/repair for more information
*************
Mon May 09 12:37:43 [initandlisten] exception in initAndListen std::exception: old lock file, 
terminating
Mon May 09 12:37:43 dbexit:
Mon May 09 12:37:43 [initandlisten] shutdown: going to close listening sockets...
Mon May 09 12:37:43 [initandlisten] shutdown: going to flush diaglog...
Mon May 09 12:37:43 [initandlisten] shutdown: going to close sockets...
Mon May 09 12:37:43 [initandlisten] shutdown: waiting for fs preallocator...
Mon May 09 12:37:43 [initandlisten] shutdown: closing all files...
Mon May 09 12:37:43 closeAllFiles() finished
Mon May 09 12:37:43 dbexit: really exiting now

Solution

This is a common error message if mongoDB machine is crashed or kill -9 command is issued. In short, your mongoDB is crashed, you have to repair it. To fix it :

1. Find the data-directory\mongod.lock file, and delete it.

mongodb lock file

2. Issue mongod --repair command.


mongod --repair
Mon May 09 12:42:57 [initandlisten] db version v1.8.1, pdfile version 4.5
//......
Mon May 09 12:42:57 [initandlisten] shutdown: going to close listening sockets...
Mon May 09 12:42:57 [initandlisten] shutdown: going to flush diaglog...
Mon May 09 12:42:57 [initandlisten] shutdown: going to close sockets...
Mon May 09 12:42:57 [initandlisten] shutdown: waiting for fs preallocator...
Mon May 09 12:42:57 [initandlisten] shutdown: closing all files...
Mon May 09 12:42:57 closeAllFiles() finished
Mon May 09 12:42:57 [initandlisten] shutdown: removing fs lock...
Mon May 09 12:42:57 dbexit: really exiting now
Note
For more detail about how mongodb repair works, please refer to this MongoDB Durability and Repair guide.

6 comments on “old lock file: \data\db\mongod.lock, probably means unclean shutdown

Leave a Comment

Your email address will not be published. Required fields are marked *