1

Running mongodb on win2012

Mongo db version v2.6.4

Our collection is created with this param:

capped:true, size:500000000000 // 500 gb

But the data dir, that only holds this one collection, has grown to 720gb.

There is no replication in use at all on this mongo server.

What can I do to keep the data dir at ~ 500 gb?

This db does get massive amounts of inserts at times, but we also need to control the max size (and let it discard old data).

Is it possible that the capped size does not include indexes?

Or is there other overhead I should account for? (and how?

Or?

db stats

> db.stats
function (scale){
    return this.runCommand( { dbstats : 1 , scale : scale } );
}
> db.stats()
{
        "db" : "logging",
        "collections" : 3,
        "objects" : 289637086,
        "avgObjSize" : 2076.3166847770317,
        "dataSize" : 601378314192,
        "storageSize" : 606012620432,
        "numExtents" : 305,
        "indexes" : 12,
        "indexSize" : 147827443456,
        "fileSize" : 776943435776,
        "nsSizeMB" : 16,
        "dataFileVersion" : {
                "major" : 4,
                "minor" : 5
        },
        "extentFreeList" : {
                "num" : 0,
                "totalSize" : 0
        },
        "ok" : 1
}
>

The command we use to create the collection:

db.createCollection("LogItem", { capped:true, size:500000000000 })

So the collection we write to is created with the capped cmd. and that is where all the space is

I can't do db.collection.stats() because out of disk space...

Thank you!

2

OK, we solved this.

Issue is that mongo auto creates the collection when incoming data comes in.

So the problem was:

  1. Drop collection
  2. // transactions are coming in
  3. Create collection as capped

But #3 comes too late, as the collection is already present, as not capped, because of #2.

Solution:

  • stop mongo
  • bring up mango on non standard port // to prevent auto creation of collection
  • create collection as capped
  • stop mongo, bring it back up on regular port

Now I have a capped collection!

0

The capped size limit applies to data but you will usually have (at least one) indexes also and those indexes are stored in the same data files.

The indexes will continue to grow as you add data to the collection. Once you fill the collection you should have an idea of the total on disk size that your 500 GB collection will take.

The reason for this has to do with the history of capped collections - the original capped collection, the oplog, which is used for replication did not have any indexes. The oplog, of course, is not replicated itself and so not having the default _id index was not a problem. However if you attempt to replicate capped collections without indexes you end up with an increasingly costly table scan in order to replicate them, which led to some serious issues.

As a result, back in version 2.2 the default behavior was changed and the _id index is added by default to capped collections. If you are not going to replicate the capped collection then you can create the collection without the default index, see the autoIndexId option here. If you create the collection this way then you will not see growth beyond the allotted amount (unless you add other indexes).

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.