How to avoid data loss on server failure with MongoDB on a single machine?
-
29-01-2021 - |
Question
I have read that mongoDB don't write data to disk right away, it does this periodically.
Any thoughts on how to deal with this?
Solution
You can enable journaling with --journal
.
Check out http://www.adathedev.co.uk/2011/03/mongodb-journaling-performance-single.html and http://www.mongodb.org/display/DOCS/Durability+and+Repair
OTHER TIPS
Besides --journal
that is enabled by default since MongoDB 2.0 (only on 64 bit machines), there is a flag that you can set when persisting data:
safe => false
: do not wait for a db responsesafe => true
: wait for a db responsesafe => num
: wait for that many servers to have the write before returningfsync => true
: fsync the write to disk before returning.fsync => true
impliessafe=>true
, but not visa versa.
If fsync=>false
and safe=>true
and the write could be in successfully applied to a mmapped file but not yet written to disk
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow