MongoDB Drop集合不釋放磁碟空間的解決辦法

chenfeng發表於2016-06-17
C:\Users\duansf>mongo
MongoDB shell version: 2.6.6
connecting to: test

> use test
switched to db test
> show collections
articles
books
chenfeng
dsf
fs.chunks
fs.files
system.indexes
system.profile
test
users


> db.books.drop();
true
>
刪除books這個collection,但是檢視資料檔案發現大小不變,MongoDB不會自動釋放檔案空間


db.repairDatabase() //執行這個命令後,Mongodb會把不需要的空間釋放出來

> db.repairDatabase()
{ "ok" : 1 }
>
注意:repairDatabase期間會產生鎖,建議關閉應用後再進行此操作

官方文件對這個命令的解釋如下:


repairDatabase requires free disk space equal to the size of your current data set plus 2 gigabytes. If the volume that holds dbpath lacks sufficient space, 
you can mount a separate volume and use that for the repair. When mounting a separate volume for repairDatabase you must run repairDatabase from the command 
line and use the --repairpath switch to specify the folder in which to store temporary repair files.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2120383/,如需轉載,請註明出處,否則將追究法律責任。

相關文章