[MongoDB] : Basic Troubleshooting

db.runCommand( { replSetGetStatus: 1 } ) – returns all members in replica set + their status.(All members should be either PRIMARY or SECONDARY)
db.printSlaveReplicationInfo() – returns sync differences between members of replica set, good values should be under a minute.

rs1:PRIMARY> use admin
switched to db admin
rs1:PRIMARY> db.runCommand( { replSetGetStatus: 1 } )
{
“set” : “rs1”,
“date” : ISODate(“2014-11-19T13:08:35Z”),
“myState” : 1,
“members” : [
{
“_id” : 0,
“name” : “dbversitydotcom:27010”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 182,
“optime” : Timestamp(1416402384, 1),
“optimeDate” : ISODate(“2014-11-19T13:06:24Z”),
“self” : true
},
{
“_id” : 1,
“name” : “dbversitydotcom:27011”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 132,
“optime” : Timestamp(1416402384, 1),
“optimeDate” : ISODate(“2014-11-19T13:06:24Z”),
“lastHeartbeat” : ISODate(“2014-11-19T13:08:33Z”),
“lastHeartbeatRecv” : ISODate(“2014-11-19T13:08:34Z”),
“pingMs” : 0,
“syncingTo” : “dbversitydotcom:27010”
},
{
“_id” : 2,
“name” : “dbversitydotcom:27012”,
“health” : 1,
“state” : 7,
“stateStr” : “ARBITER”,
“uptime” : 131,
“lastHeartbeat” : ISODate(“2014-11-19T13:08:34Z”),
“lastHeartbeatRecv” : ISODate(“2014-11-19T13:08:34Z”),
“pingMs” : 0
}
],
“ok” : 1
}
rs1:PRIMARY> db.printSlaveReplicationInfo()
source: dbversitydotcom:27011
syncedTo: Wed Nov 19 2014 08:06:24 GMT-0500 (EST)
= 142 secs ago (0.04hrs)
source: dbversitydotcom:27012
no replication info, yet. State: ARBITER
rs1:PRIMARY>

If a replica set member loses sync, shutdown mongo service and delete dbpath folder(path as defined in mongod.cfg)

To enable verbose logging, in mongod.cfg/mongod.cnf add:
verbose = true
vvvvv = true (the number of ‘v”s defines the verbose level

If the replica-set name is not explicitly defined in the mongo connection string, it will not be known to mongo c# driver!

Run “mongostat.exe –host <host> -u <username> -p <password>” to view usage statistics on specific mongod instance (refreshed every 1 sec)
[root@dbversitydotcom bin]# mongostat –port 27010
connected to: 127.0.0.1:27010
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time
*0 *0 *0 *0 0 1|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 62b 2k 8 rs1 PRI 08:10:39
*0 *0 *0 *0 0 3|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 318b 3k 8 rs1 PRI 08:10:40
*0 *0 *0 *0 0 1|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 62b 2k 8 rs1 PRI 08:10:41
*0 *0 *0 *0 1 3|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 365b 3k 8 rs1 PRI 08:10:42
*0 *0 *0 *0 0 2|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 120b 2k 8 rs1 PRI 08:10:43
*0 *0 *0 *0 0 3|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 318b 3k 8 rs1 PRI 08:10:44
*0 *0 *0 *0 0 7|0 0 1.08g 2.86g 37m 0 .:0.1% 0 0|0 0|0 434b 5k 8 rs1 PRI 08:10:45
*0 *0 *0 *0 0 3|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 318b 3k 8 rs1 PRI 08:10:46
*0 *0 *0 *0 1 1|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 109b 2k 8 rs1 PRI 08:10:47
*0 *0 *0 *0 0 3|0 0 1.08g 2.86g 37m 0 local:0.0% 0 0|0 0|0 318b 3k 8 rs1 PRI 08:10:48
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time

  • Ask Question