db.fsyncUnlock()

Definition

Important

The db.fsyncLock() and db.fsyncUnlock()operations maintain a lock count. db.fsyncLock()increments the lock count, and db.fsyncUnlock()decrements the lock count.

To unlock a mongod instance for writes, the lock countmust be zero. That is, for a given number ofdb.fsyncLock() operations, you must issue acorresponding number of db.fsyncUnlock() operations tounlock the instance for writes.

db.fsyncUnlock() is an administrative operation. Typicallyyou will use db.fsyncUnlock() following a databasebackup operation.

db.fsyncUnlock() has the syntax:

  1. db.fsyncUnlock()

The operation returns a document with the following fields:

infoInformation on the status of the operation.lockCount (New in version 3.4)The number of locks remaining on the instance after the operation.okThe status code.

The db.fsyncUnlock() method wraps thefsyncUnlock command.

Compatibility with WiredTiger

db.fsyncLock() ensures that the data files are safe to copyusing low-level backup utilities such as cp, scp, ortar. A mongod started using the copiedfiles contains user-written data that is indistinguishable from theuser-written data on the locked mongod.

The data files of a locked mongod may change due tooperations such as journaling syncs orWiredTiger snapshots. Whilethis has no affect on the logical data (e.g. data accessed byclients), some backup utilities may detect these changes and emitwarnings or fail with errors. For more information on MongoDB-recommended backup utilities and procedures, seeMongoDB Backup Methods.

Example

Consider a situation where db.fsyncLock() has been issued twotimes. The following db.fsyncUnlock() operation reduces thelocks taken by db.fsyncLock() by 1:

  1. db.fsyncUnlock()

The operation returns the following document:

  1. { "info" : "fsyncUnlock completed", "lockCount" : NumberLong(1), "ok" : 1 }

As the lockCount is greater than 0, the mongod instanceis locked against writes. To unlock the instance for writes, rundb.fsyncLock() again:

  1. db.fsyncUnlock()

The operation returns the following document:

  1. { "info" : "fsyncUnlock completed", "lockCount" : NumberLong(0), "ok" : 1 }

The mongod instance is unlocked for writes.