文档章节

mongodb 后台创建索引避免阻塞

易野
 易野
发布于 2017/07/27 15:54
字数 704
阅读 2
收藏 0
点赞 0
评论 0

By default, creating an index blocks all other operations on a database. When building an index on a collection, the
database that holds the collection is unavailable for read or write operations until the index build completes. Any
operation that requires a read or write lock on all databases (e.g. listDatabases) will wait for the foreground index
build to complete.
For potentially long running index building operations, consider the background operation so that the MongoDB
database remains available during the index building operation. For example, to create an index in the background of
the zipcode field of the people collection, issue the following:


db.people.createIndex( { zipcode: 1}, {background: true} )

 


By default, background is false for building MongoDB indexes.
You can combine the background option with other options, as in the following:
 

db.people.createIndex( { zipcode: 1}, {background: true, sparse: true } )

 

Behavior
As of MongoDB version 2.4, a mongod instance can build more than one index in the background concurrently.
Changed in version 2.4: Before 2.4, a mongod instance could only build one background index per database at a time.
Changed in version 2.2: Before 2.2, a single mongod instance could only build one index at a time.
Background indexing operations run in the background so that other database operations can run while creating the
index. However, the mongo shell session or connection where you are creating the index will block until the index
build is complete. To continue issuing commands to the database, open another connection or mongo instance.
Queries will not use partially-built indexes: the index will only be usable once the index build is complete.

Note: If MongoDB is building an index in the background, you cannot perform other administrative
operations involving that collection, including running repairDatabase, dropping the collection (i.e.
db.collection.drop()), and running compact. These operations will return an error during background
index builds.

Performance
The background index operation uses an incremental approach that is slower than the normal “foreground” index
builds. If the index is larger than the available RAM, then the incremental process can take much longer than the
foreground build.
If your application includes createIndex() operations, and an index doesn’t exist for other operational concerns,
building the index can have a severe impact on the performance of the database.
To avoid performance issues, make sure that your application checks for the indexes at start up using the
getIndexes() method or the equivalent method for your driver7 and terminates if the proper indexes do not exist.
Always build indexes in production instances using separate application code, during designated maintenance
windows.
Interrupted Index Builds
If a background index build is in progress when the mongod process terminates, when the instance restarts the index
build will restart as foreground index build. If the index build encounters any errors, such as a duplicate key error, the
mongod will exit with an error.
To start the mongod after a failed index build, use the storage.indexBuildRetry or
--noIndexBuildRetry to skip the index build on start up.

 

Building Indexes on Secondaries
Changed in version 2.6: Secondary members can now build indexes in the background. Previously all index builds on
secondaries were in the foreground.
Background index operations on a replica set secondaries begin after the primary completes building the index. If
MongoDB builds an index in the background on the primary, the secondaries will then build that index in the background.
To build large indexes on secondaries the best approach is to restart one secondary at a time in standalone mode and
build the index. After building the index, restart as a member of the replica set, allow it to catch up with the other
members of the set, and then build the index on the next secondary. When all the secondaries have the new index, step
down the primary, restart it as a standalone, and build the index on the former primary.
The amount of time required to build the index on a secondary must be within the window of the oplog, so that the
secondary can catch up with the primary.
Indexes on secondary members in “recovering” mode are always built in the foreground to allow them to catch up as
soon as possible.

 

 

 

© 著作权归作者所有

共有 人打赏支持
易野
粉丝 3
博文 148
码字总数 114303
作品 0
深圳
十个 MongoDB 使用要点

从 mongodb 阶段性技术总结 中抽取并整理了对大家有帮助的十个要点: 1.mongodb 表名和字段名统一用小写字母 mongodb 是默认区分大小写的,为了避免以前在 mysql 下遇到的大小写敏感导致程序...

旁观者-郑昀
2013/02/08
0
0
mongoDB 学习笔记纯干货(mongoose、增删改查、聚合、索引、等等)

最后更新时间:2017-07-13 11:10:49 原始文章链接:http://www.lovebxm.com/2017/07/13/mongodb_primer/ MongoDB - 简介 官网:https://www.mongodb.com/ MongoDB 是一个基于分布式文件存储的...

Airship
06/01
0
0
#转帖#MongoDB的基本特性与内部构造

MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类...

Hochikong
2015/02/26
0
0
55最佳实践系列:MongoDB最佳实践

@郑昀汇总 创建日期:2012/9 Application Design: 1)如果发现query没使用你预期的索引,请用hint强制使用指定索引 主站商品中心所使用的文档字段很多,各种索引建得也不少。在沙创排查慢查...

旁观者-郑昀
2013/02/08
0
1
mongodb 阶段性技术总结

生产环境最佳实践 1.linux 系统: 1】关闭文件系统/分区的atime 选项 Vi /etc/fstab 在对应的分区项后面添加noatime ,nodiratime LABEL=/1 / ext3 defaults 1 1LABEL=/data1 /data ext4 def...

huzorro
2012/08/21
0
3
10-【MongoDB入门教程】 Journaling日志机制

运行MongoDB如果开启了journaling日志功能,MongoDB先在内存保存写操作,并记录journaling日志到磁盘,然后才会把数据改变刷入到磁盘上的数据文件。为了保证journal日志文件的一致性,写日志...

jockchou
2015/06/24
0
3
MongoDB 4.0 事务实现解析

云数据库 MongoDB 版 了解更多 上个月底 MongoDB Wolrd 宣布发布 MongoDB 4.0, 支持复制集多文档事务,阿里云数据库团队 研发工程师第一时间对事务功能的时间进行了源码分析,解析事务实现机...

张友东
07/13
0
0
MongoDB 3.0新特性概述

MongoDB 在 2015年3月3日 跳过了 MongoDB 2.8版本,直接在 MongoDB 2.6版本后,发布了MongoDB 3.0版本。 随后在 2015年3月17日 发布了 MongoDB 3.0.1 版本; 在 2015年4月9日发布了 MongoDB ...

xinsir999
05/02
0
0
source code compiled install mongodb

文章来自我的博客:https://www.lwxshow.com/server/source-code-compiled-install-mongodb.html 源码编译安装mongodb source code compiled install mongodb 1.下载安装包 cd /usr/local/sr......

卢卫湘
2013/06/06
0
0
linux 32位与64位系统安装mongodb扩展

文章来自我的博客:https://www.lwxshow.com/server/source-code-compiled-install-mongodb.html 源码编译安装mongodb source code compiled install mongodb 1.下载安装包 cd /usr/local/sr......

卢卫湘
2013/06/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

shell中的函数、shell中的数组、告警系统需求分析

shell中的函数 格式: 格式: function f_name() { command } 函数必须要放在最前面 示例1(用来打印参数) 示例2(用于定义加法) 示例3(用于显示IP) shell中的数组 shell中的数组1 定义数...

Zhouliang6
49分钟前
2
0
用 Scikit-Learn 和 Pandas 学习线性回归

      对于想深入了解线性回归的童鞋,这里给出一个完整的例子,详细学完这个例子,对用scikit-learn来运行线性回归,评估模型不会有什么问题了。 1. 获取数据,定义问题     没有...

wangxuwei
今天
1
0
MAC安装MAVEN

一:下载maven压缩包(Zip或tar可选),解压压缩包 二:打开终端输入:vim ~/.bash_profile(如果找不到该文件新建一个:touch ./bash_profile) 三:输入i 四:输入maven环境变量配置 MAVEN_HO...

WALK_MAN
今天
0
0
33.iptables备份与恢复 firewalld的9个zone以及操作 service的操作

10.19 iptables规则备份和恢复 10.20 firewalld的9个zone 10.21 firewalld关于zone的操作 10.22 firewalld关于service的操作 10.19 iptables规则备份和恢复: ~1. 保存和备份iptables规则 ~2...

王鑫linux
今天
2
0
大数据教程(2.11):keeperalived+nginx高可用集群搭建教程

上一章节博主为大家介绍了目前大型互联网项目的系统架构体系,相信大家应该注意到其中很重要的一块知识nginx技术,在本节博主将为大家分享nginx的相关技术以及配置过程。 一、nginx相关概念 ...

em_aaron
今天
1
0
Apache Directory Studio连接Weblogic内置LDAP

OBIEE默认使用Weblogic内置LDAP管理用户及组。 要整理已存在的用户及组,此前办法是导出安全数据,文本编辑器打开认证文件,使用正则表达式获取用户及组的信息。 后来想到直接用Apache Dire...

wffger
今天
2
0
HFS

FS,它是一种上传文件的软件。 专为个人用户所设计的 HTTP 档案系统 - Http File Server,如果您觉得架设 FTP Server 太麻烦,那么这个软件可以提供您更方便的档案传输系统,下载后无须安装,...

garkey
今天
1
0
Java IO类库之BufferedInputStream

一、BufferedInputStream介绍 /** * A <code>BufferedInputStream</code> adds * functionality to another input stream-namely, * the ability to buffer the input and to * sup......

老韭菜
今天
0
0
STM 32 窗口看门狗

http://bbs.elecfans.com/jishu_805708_1_1.html https://blog.csdn.net/a1985831055/article/details/77404131...

whoisliang
昨天
1
0
Dubbo解析(六)-服务调用

当dubbo消费方和提供方都发布和引用完成后,第四步就是消费方调用提供方。 还是以dubbo的DemoService举例 -- 提供方<dubbo:application name="demo-provider"/><dubbo:registry address="z...

青离
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部