MongoDB in ReplicaSet databases showing different sizes and objects

Posted on

Question :

I have a MongoDB in a ReplicaSet with 3 members, and last week the primary node got corrupted somehow and stopped. I had to resync the data from the other nodes.

It has been a week but I was checking this morning and the databases looks different somehow between the primary (that crashed) and the two secondary that were used for resync the data.

PRIMARY (after crash)

enter image description here
enter image description here

Secondary

enter image description here
enter image description here

I’ve seen other questions similar to this one but at the end the databases had the same amount of objects, however, my scenario it isn’t the same.

Any idea? Or does it look ok?

Answer :

The rsync process will also apply a de-fragmentation for the MongoDB data files on the crashed primary replica. That’s why you see the data file reduced in size on the primary after crashed.

This effect is the same if you run the compact command on your secondary to reclaim the fragmented storage caused by data CRUD operations over time.

Leave a Reply

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