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.

migrated from stackoverflow.com Apr 29 '17 at 11:23

This question came from our site for professional and enthusiast programmers.

  • 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 Apr 29 '17 at 23:31
  • Any particular reason you don't want to configure a replicaset? – Vince Bowdren May 2 '17 at 10:14
  • @Stennie You should post this as an answer; it'll get an upvote from me. – Vince Bowdren May 2 '17 at 10:14
  • That worked for me @Stennie – sudhishkr May 2 '17 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 May 2 '17 at 20:27
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, privacy policy and cookie policy

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