 | Version 1.3.1 and higher |
The fsync command allows us to flush all pending writes to datafiles. More importantly, it also provides a lock option that makes backups easier.
Basics
The fsync command forces the database to flush all datafiles:
> use admin
> db.runCommand({fsync:1});
By default the command returns after synchronizing. To return immediately use:
> db.runCommand({fsync:1,async:true});
To fsync on a regular basis, use the --syncdelay command line option (see mongod --help output). By default a full flush is forced every 60 seconds.
Lock, Snapshot and Unlock
The fsync command supports a lock option that allows one to safely snapshot the database's datafiles. While locked, all write operations are blocked, although read operations are still allowed. After snapshotting, use the unlock command to unlock the database and allow locks again. Example:
> use admin
switched to db admin
> db.runCommand({fsync:1,lock:1})
{
"info" : "now locked against writes",
"ok" : 1
}
> db.currentOp()
{
"inprog" : [
],
"fsyncLock" : 1
}
> >
> db.$cmd.sys.unlock.findOne();
{ "ok" : 1, "info" : "unlock requested" }
> > db.currentOp()
{ "inprog" : [ ] }
See Also
IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.
These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group. blog comments powered by Disqus