日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mongodb 索引建立问题

發(fā)布時間:2024/4/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mongodb 索引建立问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
mongodb? 索引建立問題


1.主從庫索引建立不是同步建立:



?? ?MONGODB 2.6.6 版本,索引建立并不是同步的,而是主庫建立完成后,從庫接著建立索引。
?? ?不知是3.0版本是否也一樣,以前使用3.0版本也沒去監(jiān)控主從日志情況。這坑太大了。
?? ?5:00開始建立,以為主庫完成即OK.

?? ??? ?官方說明:
?? ??? ?Background index build (page 491) allowed on secondaries. If you initiate a background index build on a
?? ??? ?primary, the secondaries will replicate the index build in the background.

?? ??? ?Automatic rebuild of interrupted index builds after a restart.
?? ??? ?– If a standalone or a primary instance terminates during an index build without a clean shutdown, mongod
?? ??? ?now restarts the index build when the instance restarts. If the instance shuts down cleanly or if a user kills
?? ??? ?the index build, the interrupted index builds do not automatically restart upon the restart of the server.
?? ??? ?– If a secondary instance terminates during an index build, the mongod instance will now restart the interrupted index build when the instance restarts.
?? ??? ?To disable this behavior, use the --noIndexBuildRetry command-line option.


?? ?從庫建立索引太長時間,如果中斷從庫建立索引,可以使用 --noIndexBuildRetry? 參數(shù)重啟。
?? ?開始不知還有這個參數(shù),直接在主庫中刪除前面建立的索引了。

???

??? 網(wǎng)上看到別人是這樣處理的,感覺也不錯:

?? ??? ?1.首先把 secondary server 停止,在取消 --replSet 參數(shù),并且更改 MongoDB port 之后重新啟動 MongoDB,這時候 MongoDB 將進入 standalone 模式;

?? ??? ?2.在 standalone 模式下運行命令 ensureIndex 建立索引,建議使用 foreground 方式運行;

?? ??? ?3.建立索引完畢之后關閉 secondary server 按正常方式啟動;




?? ?下面是日志

?? ?primary:

?? ?2015-12-17T07:46:53.074+0800 [conn5530345]????????????? Index Build(background): 27309700/27314911????? 99%
?? ?。。。

?? ?slave:

?? ??? ?2015-12-17T07:46:54.985+0800 [repl index builder 14]???? building index in background
?? ??? ?2015-12-17T07:46:55.529+0800 [conn2154798] killcursors? keyUpdates:0 numYields:0 locks(micros) r:73 167ms
?? ??? ?2015-12-17T07:46:58.226+0800 [repl index builder 14]??????????? Index Build(background): 4700/27314911? 0%





2.TTL 索引刪除數(shù)據(jù),不是一次性刪除超出日期的數(shù)據(jù),而是一點點來的,

?? ?也是一樣,以前一直以為是索引建立后,TTL 刪除數(shù)據(jù)是一次性操作,那里知道幾個小時也沒刪除完成,導致數(shù)據(jù)庫
?? ?壓力一直很高。

?? ?后來只好先改名,再建立好新表后把數(shù)據(jù)插入進去。
?? ?db.WebLog.renameCollection("WebLog_bak");
?? ?db.WebLog.ensureIndex({MallID:1,Mac:1});
?? ?db.WebLog.ensureIndex({CreateTime:-1},{expireAfterSeconds:3600*24*3*30});

?? ?var cursor=db.WebLog_bak.find({_id:{$gte:24600000}});
?? ?while (cursor.hasNext()){
?? ?? nc=cursor.next();
?? ?? db.WebLog.insert(nc);
?? ?};

總結

以上是生活随笔為你收集整理的mongodb 索引建立问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。