0

My problem is with Mongo eating up space on the disk.

Reading a few blogs no the web - I was certain - a repair would save me time as this would free up mongo's reserved space. But attempting a repair throws this error because I am at 90% disk usage :

db.repairDatabase()
{
    "ok" : 0,
    "errmsg" : "Cannot repair database my_d_b having size: 347673198592 (bytes) because free disk space is: 42874580992 (bytes)"
}

Then I tried the next step which is compacting every collection in the database using :

db.getCollectionNames().forEach(function (collectionName) {
  print('Compacting: ' + collectionName);
  db.runCommand({ compact: collectionName });
});

This reduced my disk usage by just 1%.

Now I can easily pause my apps from writing to this mongo database. I don't want to use any replset approach etc. I want to just move it to a bigger disk and move forward. I have already mounted an extra disk which 2.5times the size. I am not finding concrete steps to move the data and change mongo configuration and then start mongo process.

My repairs and compactions may be failing because they need space to operate as per my understading. If I can move this data to new disk and point mongo to the new disk, I will be good.

This is what I want to achieve - would appreciate a little direction.

6
  • 2
    It sounds like you have a standalone server and are OK stopping mongod ? If so, the most direct approach would be to copy the contents of your current dbPath to the a directory on the new disk: stop mongod, copy the contents of your dbPath to a new directory, update dbPath in your configuration file to point to this new directory, and finally restart mongod. As far as trying to reduce existing storage usage: can you confirm the specific version of MongoDB and storage engine are you using?
    – Stennie
    Commented Apr 29, 2017 at 23:31
  • Any particular reason you don't want to configure a replicaset? Commented May 2, 2017 at 10:14
  • @Stennie You should post this as an answer; it'll get an upvote from me. Commented May 2, 2017 at 10:14
  • That worked for me @Stennie
    – sudhishkr
    Commented May 2, 2017 at 20:26
  • @VinceBowdren - i just dont want to go that route for now, may be in future. Can afford a down-time - wanted to keep this simple.
    – sudhishkr
    Commented May 2, 2017 at 20:27

1 Answer 1

2

If you have a standalone MongoDB server and can tolerate downtime, the most direct approach would be to copy the contents of your current dbPath to a directory on the new disk:

  • Stop mongod
  • Copy the contents of your dbPath to a directory on the new disk
  • Update dbPath in your configuration file to point to this new directory
  • Finally, restart mongod

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.