Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Anuja K
8 years ago

It does work well in recovering the data. However after every few days, I have to run repair. We shutdown by Control-C. Any permanent fix for this?

Thoman
9 years ago

Thanks

Luxedrina
9 years ago

Thanks, it works :).

jay singh rana
9 years ago

thank you it helps me……..

Hao
11 years ago

Thank you about document. It’s helpfull for me.

netaji
11 years ago

Very very helpful information for beginers !