MongoDB释放磁盘空间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MongoDB释放磁盘空间相关的知识,希望对你有一定的参考价值。

1. 先删除旧的文档db.remove({});

2. 从副本集中移除待清理的成员:

  (1) 登录副本集中的 Primary 服务器(/opt/mongo1/bin/mongo --port 27017)

  (2) rs.remove("192.168.1.54:27019")

3. 关闭待清理的 mongodb 服务器

  (1) 登录待清理的 mongodb 服务器(/opt/mongo2/bin/mongo --port 27018)

  (2) user admin; db.shutdownServer();

4. 修改 mongodb 启动参数,并运行

  bin/mongod --dbpath /home/mongodata2/data --port 27018 --logpath=/home/mongodata2/logs/mongodb2.log --repair --repairpath /opt/data

5. 确认 mongod 运行结束

  可以用 ps axu | grep mongod 查看进程是否结束。
  也可以看日志文件 /home/mongodata2/logs/mongodb2.log 是否有如下输出:

  2016-05-10T13:14:41.646+0800 [conn5413] dbexit: shutdown called
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to close listening sockets...
  2016-05-10T13:14:41.646+0800 [conn5413] closing listening socket: 8
  2016-05-10T13:14:41.646+0800 [conn5413] closing listening socket: 10
  2016-05-10T13:14:41.646+0800 [conn5413] removing socket file: /tmp/mongodb-27018.sock
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to flush diaglog...
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to close sockets...
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: waiting for fs preallocator...
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: lock for final commit...
  2016-05-10T13:14:41.646+0800 [conn5413] shutdown: final commit...
  2016-05-10T13:14:41.647+0800 [conn5413] shutdown: closing all files...
  2016-05-10T13:14:41.832+0800 [conn5413] closeAllFiles() finished
  2016-05-10T13:14:41.832+0800 [conn5413] journalCleanup...
  2016-05-10T13:14:41.832+0800 [conn5413] removeJournalFiles
  2016-05-10T13:14:41.889+0800 [conn5413] shutdown: removing fs lock...
  2016-05-10T13:14:41.889+0800 [conn5413] dbexit: really exiting now

6. 最后以正常方式启动 mongod,并将成员加入到副本集中

  登录副本集中的 Primary 服务器

  rs.add("IPADDR:27018")

  查看副本集的运行结果:  rs.printSlaveReplicationInfo()

















以上是关于MongoDB释放磁盘空间的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB repairDatabase 释放磁盘空间

MongoDB释放磁盘空间

MongoDB如何释放空闲空间?

DB2 删除表后如何释放相应磁盘空间

linux 删除文件后,如何释放磁盘空间

MongoDB: 数据库复制