How to avoid data loss on server failure with MongoDB on a single machine?
Asked Answered
U

2

6

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?

Upthrust answered 26/9, 2011 at 4:14 Comment(1)
Have you read the MongoDB docs? mongodb.org/display/DOCS/JournalingHypsography
S
5

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

Soper answered 26/9, 2011 at 4:20 Comment(3)
From MongoDB v2.0, jounaling is enabled by default.Bolten
Just to clarify -- journal by default enabled in 2.0 at 64 bit machines.Neckline
And only in 64 bit machines :)Soper
R
3

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 response
  • safe => true: wait for a db response
  • safe => num: wait for that many servers to have the write before returning
  • fsync => true: fsync the write to disk before returning. fsync => true implies safe=>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

Reset answered 27/9, 2011 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.