content_image/749759.jpg
<img src='content_image/749759.jpg'>

## 11.4.6 Which administrative commands lock the database? 

Certain administrative commands can exclusively lock the database for extended periods of time. In some deploy- ments, for large databases, you may consider taking the mongod instance offline so that clients are not affected. For example, if a mongod is part of a replica set , take the mongod offline and let other members of the set service load while maintenance is in progress. 

The following administrative operations require an exclusive (i.e. write) lock on the database for extended periods: 

• db.collection.createIndex() , when issued without setting background to true , 

• reIndex , 

• compact , 

• db.repairDatabase() , 

• db.createCollection() , when creating a very large (i.e. many gigabytes) capped collection, 

• db.collection.validate() , and 

• db.copyDatabase() . This operation may lock all databases. See Does a MongoDB operation ever lock more than one database? (page 761). 

The following administrative commands lock the database but only hold the lock for a very short time: 

• db.collection.dropIndex() , 

• db.getLastError() , 

• db.isMaster() , 

• rs.status() (i.e. replSetGetStatus ), 

• db.serverStatus() , 

• db.auth() , and 

• db.addUser() . 

