3

I am having a space problem with mongoDB and my current ubuntu 12.04 desktop computer. I always used the default setting which means that the data is physically stored under /var/lib/mongodb. By the time the database size grew vastly and now I would like to drop some collections to have some empty space in my hard drive. I have checked this and other methods But whenever I run the remove function I keep getting the following error message:

Can't take a write lock while out of disk space

The first solution came to my mind is to set the path of mongodb to an external harddisk or a usb disk and physically remove the folder using rm -rf. Would that be a safe solution? Are there any other solutions to this problem?

2
  • You should first copy the datafiles to the external disk, otherwise that would delete all your data :) But yes, in principle, that can solve the problem. With more disk available, you can selectively delete data and use compaction. Alternatively, you can try to do a mongodump to the external disk, remove the collection files you don't need, remove the data files, and re-import the data. Needless to say, always have a backup. Commented Feb 25, 2014 at 9:43
  • also you could try removing some other files that are on your hard drive so that mongo could get some more space and be able to do the drops. Commented Feb 25, 2014 at 9:50

1 Answer 1

3

Mongodb is very good for copying databases as all you have to do is copy the full data directory to somewhere else and then you can just point a new mongod process at it and it will work.

Therefore your steps are:

  • Find the current data directory
  • Copy this to another location
  • Delete any file that has .lock in the directory (this stops Mongo from loading up again)
  • Now start up another mongo with the following command:

    mongod --dbpath <path to new directory on new disk> --port 27020
    

This will now open up a new mongo database (but on a different port to avoid any issues with a mongod that may already be running). Now you will have a new mongod running against the new disk without needing to delete collections \ dbs. Remember that Mongodb is greedy and doesn't willingly give up disk space when you delete a collection. You'll need to run

 db.repairDatabase()

Once you're happy, you can safely delete the old mongodb data directory and then copy the new one over it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.