Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why has my newly created mongodb local database grown to 24GB?

Tags:

mongodb

I setup a mongodb replica set a few days ago, I did some little test on it and everything working well. Today I just found its local collection grew to 24G !!!

rs0:PRIMARY> show dbs
local   24.06640625GB
test    0.203125GB

The other collections look normal except "oplog.rs":

rs0:PRIMARY> db.oplog.rs.stats()
{
    "ns" : "local.oplog.rs",
    "count" : 322156,
    "size" : 119881336,
    "avgObjSize" : 372.12200300475547,
    "storageSize" : 24681987920,
    "numExtents" : 12,
    "nindexes" : 0,
    "lastExtentSize" : 1071292416,
    "paddingFactor" : 1,
    "systemFlags" : 0,
    "userFlags" : 0,
    "totalIndexSize" : 0,
    "indexSizes" : {

    },
    "capped" : true,
    "max" : NumberLong("9223372036854775807"),
    "ok" : 1
}

This is my mongodb.conf

dbpath=/data/db

#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
port = 27017
fork = true
replSet = rs0

How can I solve it? Many thanks.

like image 515
blackgun Avatar asked Sep 27 '13 20:09

blackgun


People also ask

How much memory is needed for MongoDB?

MongoDB requires approximately 1 GB of RAM per 100.000 assets. If the system has to start swapping memory to disk, this will have a severely negative impact on performance and should be avoided.

How many database can be created in MongoDB?

By default, you can run some 12,000 collections in a single instance of MongoDB( that is, if each collection also has 1 index).

Where does MongoDB store data locally?

log and the database is stored in /usr/local/var/mongodb . By default there is no access control, anyone can read and write to the database.

Why is MongoDB High Availability?

MongoDB is one such database that can provide high availability for the MongoDB databases by using features like sharding and replication. If the system crashes or the hardware or software faces any issues, replication processes in the databases help you recover and backup your system.


1 Answers

The oplog, which keeps an ongoing log for the operations on the primary and is used for the replication mechanism, is allocated by default at 5% of the available free disk space (for Linux/Unix systems, not Mac OS X or Windows). So if you have a lot of free disk space, MongoDB will make a large oplog, which means you have a large time window within which you could restore back to any point in time, for instance. Once the oplog reaches its maximum size, it simply rolls over (ring buffer).

You can specify the size of the oplog when initializing the database using the oplogSize option, see http://docs.mongodb.org/manual/core/replica-set-oplog/

Bottom line: Unless you are really short of disk space (which apparently you aren't, otherwise the oplog wouldn't have been created so big), don't worry about it. It provides extra security.

like image 125
drmirror Avatar answered Oct 02 '22 13:10

drmirror