Image saving behavior for partially changed files
4 posts
When I set the software to save the RAM disk to an image, either on shutdown or on a timer, does it rewrite the entire file if only part of it has changed?
For example, there's a 2GB SQLite database file in my RAM drive. Part of it has changed, but 99% of the file is unchanged. Will the entire file be rewritten to my SSD, or only the changed portion?
Thank you.
Only the changed blocks are written to the image file, not the entire file.
Additionally, the image files are sparse, meaning they only occupy disk space for the portions that have actually been written.
Great, thank you! Then I can backup the database to disk regularly without worrying about SSD wear.
That is correct: SSD wear would be minimal.
However, it is worth noting that a database typically performs random I/O, whereas periodically writing an image (snapshot) of the database is usually sequential. If both processes run concurrently (i.e. the database is being written to while the snapshot is being taken), there is a small risk that the snapshot could capture a partially updated state, resulting in an inconsistent image.
This risk is reduced if the database uses write-ahead logging (WAL), since WAL helps ensure transactional consistency and makes it possible to recover a consistent state even if a snapshot is taken during active writes.