How to make MongoDB `repairDatabase` and `compact` commands work with replica-set? Downtime is ok

Viewed 4617

We need to free some of our MongoDB space, and we identified 100Gb + worth of documents that can be safely removed from a collection.

So we removed them from our test environment which has this setting:

  • mongodb version 3.0.1
  • no sharding
  • 1 node, no replica
  • wiredtiger engine

When done, we found out that the space on disk was still used and needed to be reclaimed. We found this post and it helped us: after running both

db.runCommand({repairDatabase: 1})

and

db.runCommand({compact: collection-name })

We freed 100Gb +.

We then proceeded in production, forgetting that the setting was different since we had 1 replica node:

  • mongodb version 3.0.1
  • no sharding
  • 1 primary node, 1 replica node
  • wiredtiger engine

After removing the documents, we run

db.runCommand({repairDatabase: 1})

and got the OK message (after a while, 10 min +). We tried running

db.runCommand({compact: collection-name })

and got this error:

will not run compact on an active replica set primary as this is a slow blocking operation. use force:true to force

So we run

db.runCommand({compact: collection-name, force: true })

and got the OK message (almost instantly), but the disk on space is still used, it wasn't freed.

we searched for solutions for running the repairDatabase and compact commands with replica-set but the advise was focused on avoiding downtime as if that was the only issue. However, we can schedule downtime and our problem is rather that the commands don't work as expected since the space is not actually reclaimed.

What did we do wrong?

1 Answers
Related