fsync Befehle

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 
} 

> // do some work here: for example, snapshot datafiles... 
>// runPogram("/path/to/my-filesystem-snapshotting-script.sh") 

> db.$cmd.sys.unlock.findOne(); 
{ "ok" : 1, "info" : "unlock requested" } 
> // unlock is now requested. it may take a moment to take effect. 
> db.currentOp() 
{ "inprog" : [ ] } 

See Also


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

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