SSD Devices and Data Corruption


Database servers ensure that when a transaction is committed, the information is written physically to the storage and cannot be lost any more in case of power failure.

Database servers also use a journal file during operations that modify the data, writing information in it that can be used to recover the original state of the data in case of power failure during the updates, and avoid database corruption.

That’s why the database server must ensure that at specific points in the modification process, data that are still in the device cache are flushed to the SSD cells.

To achieve this, the database server calls frequently the Unix system function fdatasync, that requires the device to flush the data still pending in its internal cache and write them physically to the SSD cells. Unfortunately, physically writing to the SSD cells is a very inefficient and slow process (compared to writes to the internal cache), but this is the only means to ensure durability and avoid file corruption. Alas, performances are degraded so much that other solutions have been found.

SSD devices exist in two kinds: consumer-grade and enterprise-grade.

We must consider these different cases:

So, even if the internal cache of the SSD is inherently volatile, the laptop makes it safe by using its own battery. And the enterprise-grade SSDs makes the internal cache safe by embedding large capacitors.
For both cases, the operations on the SSD will always use the internal cache, avoiding the sluggish physical writes to the cells. This also has the advantage of reducing the SSD wear out, increasing the life of the device.

Data Corruption

Data corruption can occur when the main power supply fails.

The voltage doesn’t drop instantly, and it will take a little time (a few milliseconds) to drop to 0. Some components of a computer will fails before the others. The RAM is quite vulnerable to voltage drop, more than hard disks or SSDs. The RAM will start to fail and will send garbage to the hard disk or SSD, which will happily write it all.

If you pull the plug of a server during heavy writes, you can end up with a database corruption. So, don’t do that.

RSQL, a simple alternative to Microsoft SQL Server