How to shrink oplog.rs

495 views
Skip to first unread message

Justin

unread,
Sep 24, 2013, 5:08:04 AM9/24/13
to mongod...@googlegroups.com
My local.oplog.rs collection is 16GB. Is there anyway to reclaim that wasted free space? Can I do a repair database on it?

Sam Millman

unread,
Sep 24, 2013, 6:46:47 AM9/24/13
to mongod...@googlegroups.com


On 24 September 2013 10:08, Justin <comm...@nodesocket.com> wrote:
My local.oplog.rs collection is 16GB. Is there anyway to reclaim that wasted free space? Can I do a repair database on it?

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Message has been deleted

Linda Xu

unread,
Feb 12, 2014, 11:38:38 AM2/12/14
to mongod...@googlegroups.com
This is old post but I was looking for a clear steps to shrink our op log from 133GB down to 15GB and I did not find a straight answer. We finally successfully shrink the log and I am posting steps here, and hope it can help same people like us.

10gen/mongodb's document steps for change oplog size will work fine for increase the op logs size and change the collection size of oplog but it did not release the waste space.

http://docs.mongodb.org/manual/tutorial/change-oplog-size/

There are 2 ways to release wasted database size.
1. run database repair command (db.repairdatabase)
2. mongodump the database, drop database, recreate db by using mongorestore

We choice the method 2 in our production. Method 1 also worked in our testing env but consider the big size of op log, we used method 2
here is the steps

0. Restart replica as standalone before next step.
(comment out repSet in configure file and  start mongodb instance with different port, for example 28017here)

1.find the last entry and save it to temp

use local or db = db.getSiblingDB('local')
db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
db.temp.find()


2. drop local database's oplog collection
db = db.getSiblingDB('local')
db.oplog.rs.drop()

3. create new oplogs with 15GB
db.runCommand( { create: "oplog.rs", capped: true, size: (15 * 1024 * 1024 * 1024) } )

4.insert last entry
db.oplog.rs.save( db.temp.findOne() )

5.double check it
db.oplog.rs.find();

6. If you are increase op log, skip following steps and go to last one for restart mongodb.

For shrink op log and release space from local database

run a mongodump by make a new directory
cd
mkdir localcopy
cd localcopy

mongodump --port 28017 -u admin -p -d local

7.drop local database (will finally release the space)
use local
db.dropDatabase()

8.mongorestore (will recreate local with smaller size)
cd localcopy
mongorestore --port 28017 -u admin -p

9. restart database to double check. ops.rs record

use local
db.oplog.rs.find();


10. restart mongodb with repSet and default port. Repeat same step for different member of replica set.
Reply all
Reply to author
Forward
0 new messages