[英]Deleting MongoDB database and collections
I am having a space problem with mongoDB and my current ubuntu 12.04 desktop computer. 我的mongoDB和当前的ubuntu 12.04台式计算机存在空间问题。 I always used the default setting which means that the data is physically stored under /var/lib/mongodb.
我一直使用默认设置,这意味着数据实际存储在/ 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:
我已经检查了此方法和其他方法,但是每当我运行remove函数时,我都会不断收到以下错误消息:
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
. 我想到的第一个解决方案是将mongodb的路径设置为外部硬盘或USB磁盘,然后使用
rm -rf
物理删除该文件夹。 Would that be a safe solution? 那是一个安全的解决方案吗? Are there any other solutions to this problem?
还有其他解决方案吗?
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. Mongodb对于复制数据库非常有用,因为您要做的就是将完整的数据目录复制到其他位置,然后只需在它上指向一个新的mongod进程即可。
Therefore your steps are: 因此,您的步骤是:
Now start up another mongo with the following command: 现在,使用以下命令启动另一个mongo:
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). 现在,这将打开一个新的mongo数据库(但在另一个端口上,以避免可能已经在运行的mongod出现任何问题)。 Now you will have a new mongod running against the new disk without needing to delete collections \\ dbs.
现在,您将在新磁盘上运行一个新mongod,而无需删除collections \\ dbs。 Remember that Mongodb is greedy and doesn't willingly give up disk space when you delete a collection.
请记住,Mongodb贪婪,并且在删除集合时不会自愿放弃磁盘空间。 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. 满意后,您可以安全地删除旧的mongodb数据目录,然后在其上复制新目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.