修改(Secondary,Primary set)Oplog文件大小

本文提供了一套详细的步骤来指导如何在MongoDB中扩容Oplog,包括重启节点、备份Oplog、创建新的Oplog及转移最后一条记录等关键操作。适用于需要进行滚动维护的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Restart a Secondary in Standalone Mode on a Different Port

  db.shutdownServer()

  mongod --port 37017 --dbpath /data/standby

2.Create a Backup of the Oplog (Optional)
 
  mongodump --db local --collection 'oplog.rs' --port 37017

3.Recreate the Oplog with a New Size and a Seed Entry
  
  use local
  db = db.getSiblingDB('local')
  db.temp.drop()
  db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
  db.temp.find()

4.Remove the Existing Oplog Collection

  db = db.getSiblingDB('local')
  db.oplog.rs.drop()

5.Create a New Oplog
  
  db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024) } )   //2MB
  
6.Insert the Last Entry of the Old Oplog into the New Oplog
  
  db.oplog.rs.save( db.temp.findOne() )
  db.oplog.rs.find()

7.Restart the Member
  
  db.shutdownServer()
  mongod --replSet "rs0" --dbpath /data/standby

8.查看日志文件大小
  rs0:SECONDARY> use local
  switched to db local
  rs0:SECONDARY> db.oplog.rs.totalSize()
  2097152  //2MB

8.Change the Size of the Oplog on the Primary

  To finish the rolling maintenance operation, step down the primary with the rs.stepDown() method and repeat the oplog resizing procedure above.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值