[SERVER-4338] Compact command results in (much) larger database Created: 21/Nov/11  Updated: 22/Nov/11  Resolved: 22/Nov/11

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Joost de Vries Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

CentOS 5.6


Operating System: Linux
Participants:

 Description   

After I've run an inline compaction, the DB actually grows in size. I've seen this happening on my production environment (where I actually ran out of RAM because of this) and I've just reproduced it on my development environment.

After running db.repairDatabase() the size shrinks back.

Below is the Mongo shell output:

> show dbs
admin (empty)
local (empty)
test (empty)
mydb 1.953125GB
> db.mycollection.runCommand('compact')

{ "ok" : 1 }

> show dbs
admin (empty)
local (empty)
test (empty)
mydb 3.9521484375GB
> db.stats()

{ "db" : "mydb", "collections" : 7, "objects" : 1017491, "avgObjSize" : 588.1718894810863, "dataSize" : 598459604, "storageSize" : 635535360, "numExtents" : 29, "indexes" : 5, "indexSize" : 77868224, "fileSize" : 4226809856, "nsSizeMB" : 16, "ok" : 1 } > db.repairDatabase() { "ok" : 1 }

> db.stats()
{
"db" : "mydb",
"collections" : 7,
"objects" : 1017491,
"avgObjSize" : 588.1718894810863,
"dataSize" : 598459604,
"storageSize" : 705445888,
"numExtents" : 44,
"indexes" : 5,
"indexSize" : 75938688,
"fileSize" : 2080374784,
"nsSizeMB" : 16,
"ok" : 1
}
> show dbs
admin (empty)
local (empty)
test (empty)
mydb 1.953125GB



 Comments   
Comment by Eliot Horowitz (Inactive) [ 22/Nov/11 ]

compact has to increase db size originally so it has space to do the copy.
It never will return space to the filesystem.
The collection should be less space if it was fragmented.

Also, there is an issue with repeated compacts, see: SERVER:3791

Generated at Thu Feb 08 03:05:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.