- Reference >
- mongo Shell Methods >
- 数据库相关方法 >
- db.fsyncLock()
db.fsyncLock()¶
On this page
Definition¶
- db.fsyncLock()¶
Forces the mongod to flush all pending write operations to disk and locks the entire mongod instance to prevent additional writes until the user releases the lock with the db.fsyncUnlock() command. db.fsyncLock() is an administrative command.
This command provides a simple wrapper around a fsync database command with the following syntax:
{ fsync: 1, lock: true }
This function locks the database and creates a window for backup operations.
Behavior¶
Compatibility with WiredTiger¶
在 3.2 版更改: db.fsyncLock() can ensure that the data files do not change for MongoDB instances using either the MMAPv1 or the WiredTiger storage engines, thus providing consistency for the purposes of creating backups.
In previous MongoDB versions, db.fsyncLock() cannot guarantee a consistent set of files for low-level backups (e.g. via file copy cp, scp, tar) for WiredTiger.
Impact on Read Operations¶
db.fsyncLock() may block reads, including those necessary to verify authentication. Such reads are necessary to establish new connections to a mongod that enforces authorization checks.
Connection¶
When calling db.fsyncLock(), ensure that the connection is kept open to allow a subsequent call to db.fsyncUnlock().
Closing the connection may make it difficult to release the lock.