Changing the oplog's size

Hand in hand with the previous operational tip, we may need to rethink and resize our oplog as our data grows. Operations become more complicated and time-consuming as our data grows, and we need to adjust our oplog size to accommodate for it. The steps for changing the oplog's size are as follows:

  1. The first step is to restart our MongoDB secondary server as a standalone server, an operation that was described in the How to perform maintenance on replica sets section.
  2. We then make a backup of our existing oplog:
> mongodump --db local --collection 'oplog.rs' --port 37017
  1. We keep a copy of this data, just in case. We then connect to our standalone database:
> use local
> db = db.getSiblingDB('local')
> db.temp.drop()

Up until now, we have connected to the local database and deleted the temp collection, just in case it had any leftover documents.

  1. The next step is to get the last entry of our current oplog and save it in the temp collection:
> db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )

  1. This entry will be used when we restart our secondary server, in order to track where it has reached in the oplog replication:
> db = db.getSiblingDB('local')
> db.oplog.rs.drop()
  1. Now, we delete our existing oplog, and in the next step, we will create a new oplog of 4 GB in size:
> db.runCommand( { create: "oplog.rs", capped: true, size: (4 * 1024 * 1024 * 1024) } )
  1. The next step is to copy the one entry from our temp collection back to our oplog:
> db.oplog.rs.save( db.temp.findOne() )
  1. Finally, we cleanly shut down our server from the admin database, using the db.shutdownServer() command, and we restart our secondary as a member of the replica set.
  2. We repeat this process for all secondary servers, and as a last step, we repeat the procedure for our primary member, which is done after we step the primary down by using the following command:
> rs.stepDown(600)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset