`

MongoDB非正常关闭后修复记录

阅读更多

MongoDB非正常关闭后修复记录

mongod没有后台执行,在终端连接非正常断开后,再次执行mongod报错,如下所示:

[root@sunrise16 bin]# ./mongod
./mongod --help for help and startup options
Tue Oct 25 19:49:02
Tue Oct 25 19:49:02 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Oct 25 19:49:02
Tue Oct 25 19:49:02 [initandlisten] MongoDB starting : pid=13626 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Tue Oct 25 19:49:02 [initandlisten]
Tue Oct 25 19:49:02 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Oct 25 19:49:02 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Oct 25 19:49:02 [initandlisten] **       with --journal, the limit is lower
Tue Oct 25 19:49:02 [initandlisten]
Tue Oct 25 19:49:02 [initandlisten] db version v2.0.0, pdfile version 4.5
Tue Oct 25 19:49:02 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Tue Oct 25 19:49:02 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Tue Oct 25 19:49:02 [initandlisten] options: {}
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Tue Oct 25 19:49:02 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Tue Oct 25 19:49:02 dbexit:
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 25 19:49:02 [initandlisten] shutdown: going to close sockets...
Tue Oct 25 19:49:02 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 25 19:49:02 [initandlisten] shutdown: closing all files...
Tue Oct 25 19:49:02 [initandlisten] closeAllFiles() finished
Tue Oct 25 19:49:02 dbexit: really exiting now

 

http://www.mongodb.org/display/DOCS/Durability+and+Repair#DurabilityandRepair-RepairCommand 写道
Repair Command

When not using journaling (--nojournal), after a machine crash or kill -9 termination, run the repairDatabase command. This command will check all data for corruption, remove any corruption found, and compact data files a bit. Repair is analogous to running fsck for a file system.

When journaling is enabled, it should not be necessary to run repair. However one could still use the repair command to compact a database.

From the command line:

mongod --repair

From the shell (you have to do for all dbs including local if you go this route):

> db.repairDatabase();

During a repair operation, mongod must store temporary files to disk. By default, mongod creates temporary directories under the dbpath for this purpose. Alternatively, the --repairpath command line option can be used to specify a base directory for temporary repair files.

Note that repair is a slow operation which inspects the entire database.

After running with --repair, mongod will start up normally.
 

现在执行修复。
[root@sunrise16 bin]# ./mongod --repair
Tue Oct 25 19:50:21
Tue Oct 25 19:50:21 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Oct 25 19:50:21
Tue Oct 25 19:50:21 [initandlisten] MongoDB starting : pid=14452 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Tue Oct 25 19:50:21 [initandlisten]
Tue Oct 25 19:50:21 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Oct 25 19:50:21 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Oct 25 19:50:21 [initandlisten] **       with --journal, the limit is lower
Tue Oct 25 19:50:21 [initandlisten]
Tue Oct 25 19:50:21 [initandlisten] db version v2.0.0, pdfile version 4.5
Tue Oct 25 19:50:21 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Tue Oct 25 19:50:21 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Tue Oct 25 19:50:21 [initandlisten] options: { repair: true }
Tue Oct 25 19:50:22 [initandlisten] ****
Tue Oct 25 19:50:22 [initandlisten] ****
Tue Oct 25 19:50:22 [initandlisten] need to upgrade database mydb with pdfile version 4.5, new version: 4.5
Tue Oct 25 19:50:22 [initandlisten]      starting upgrade
Tue Oct 25 19:50:22 [initandlisten]  mydb repairDatabase mydb
Tue Oct 25 19:50:22 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/mydb.ns, filling with zeroes...
Tue Oct 25 19:50:22 [FileAllocator] creating directory /data/db/$tmp_repairDatabase_0/_tmp
Tue Oct 25 19:50:26 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/mydb.ns, size: 16MB,  took 4 secs
Tue Oct 25 19:50:26 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/mydb.0, filling with zeroes...
Tue Oct 25 19:50:30 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/mydb.0, size: 16MB,  took 4.004 secs
Tue Oct 25 19:50:30 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/mydb.1, filling with zeroes...
Tue Oct 25 19:50:30 [initandlisten] build index mydb.things { _id: 1 }
Tue Oct 25 19:50:30 [initandlisten] build index done 22 records 0.008 secs
Tue Oct 25 19:50:38 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/mydb.1, size: 32MB,  took 7.981 secs
Tue Oct 25 19:50:38 [initandlisten] ****
Tue Oct 25 19:50:38 [initandlisten] ****
Tue Oct 25 19:50:38 [initandlisten] need to upgrade database test with pdfile version 4.5, new version: 4.5
Tue Oct 25 19:50:38 [initandlisten]      starting upgrade
Tue Oct 25 19:50:38 [initandlisten]  test repairDatabase test
Tue Oct 25 19:50:38 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/test.ns, filling with zeroes...
Tue Oct 25 19:50:38 [FileAllocator] creating directory /data/db/$tmp_repairDatabase_0/_tmp
Tue Oct 25 19:50:42 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/test.ns, size: 16MB,  took 3.995 secs
Tue Oct 25 19:50:42 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/test.0, filling with zeroes...
Tue Oct 25 19:50:46 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/test.0, size: 16MB,  took 4.06 secs
Tue Oct 25 19:50:46 [FileAllocator] allocating new datafile /data/db/$tmp_repairDatabase_0/test.1, filling with zeroes...
Tue Oct 25 19:50:46 [initandlisten] build index test.foo { _id: 1 }
Tue Oct 25 19:50:46 [initandlisten] build index done 1 records 0 secs
Tue Oct 25 19:50:54 [FileAllocator] done allocating datafile /data/db/$tmp_repairDatabase_0/test.1, size: 32MB,  took 8.031 secs
Tue Oct 25 19:50:54 [initandlisten] finished checking dbs
Tue Oct 25 19:50:54 dbexit:
Tue Oct 25 19:50:54 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 25 19:50:54 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 25 19:50:54 [initandlisten] shutdown: going to close sockets...
Tue Oct 25 19:50:54 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 25 19:50:54 [initandlisten] shutdown: closing all files...
Tue Oct 25 19:50:54 [initandlisten] closeAllFiles() finished
Tue Oct 25 19:50:54 [initandlisten] shutdown: removing fs lock...
Tue Oct 25 19:50:54 dbexit: really exiting now

 

现在正常启动mongod。
[root@sunrise16 bin]# ./mongod
./mongod --help for help and startup options
Tue Oct 25 19:51:00
Tue Oct 25 19:51:00 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Oct 25 19:51:00
Tue Oct 25 19:51:00 [initandlisten] MongoDB starting : pid=14459 port=27017 dbpath=/data/db/ 32-bit host=sunrise16
Tue Oct 25 19:51:00 [initandlisten]
Tue Oct 25 19:51:00 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Tue Oct 25 19:51:00 [initandlisten] **       see http://blog.mongodb.org/post/137788967/32-bit-limitations
Tue Oct 25 19:51:00 [initandlisten] **       with --journal, the limit is lower
Tue Oct 25 19:51:00 [initandlisten]
Tue Oct 25 19:51:00 [initandlisten] db version v2.0.0, pdfile version 4.5
Tue Oct 25 19:51:00 [initandlisten] git version: 695c67dff0ffc361b8568a13366f027caa406222
Tue Oct 25 19:51:00 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Tue Oct 25 19:51:00 [initandlisten] options: {}
Tue Oct 25 19:51:00 [initandlisten] waiting for connections on port 27017
Tue Oct 25 19:51:00 [websvr] admin web console waiting for connections on port 28017

Tue Oct 25 19:52:00 [clientcursormon] mem (MB) res:12 virt:92 mapped:0
Tue Oct 25 19:57:00 [clientcursormon] mem (MB) res:12 virt:92 mapped:0

 

...

 

 

 

2
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics