Skip to content

RocksDB best practices

Denis Fakhrtdinov edited this page Feb 14, 2025 · 2 revisions

Avoid column-family tables

Column-family tables are not supported by LevelDB (RocksDB) repair tool, so it is better to avoid it unless all the data in the table, including the data in different column families, must be consistent.

Configure column-families tables properly

If the data in column-family tables must be consistent between families, make sure the atomic flush option is set; this will make RocksDB dump and flush all the data for all the column families at the same time, ensuring consistency.

Flush memtables and sync WALs periodically

RocksDB relies on OS-level mechanisms in order to sync data to the disk, but in case of hardware issues this will not help, as the data will be lost with the OS reboot. In order to reduce the chance of losing the data, perform periodic memtables flushes and write-ahead logs syncs, that will force OS to sync data to the disk. The interval between sync calls is a tradeoff between speed and reliability.

Use sync mode for critical data

Sync mode will dump all the data to the disk every time the data is written to the table. In some scenarios this is the desired behavior.

Avoid (semi-)automatic repairs with repair tool

Repair tool most likely will not do what you expect: it will read the database MANIFEST and try to rebuild it reading the data from memtables found on disk. In case the memtable file is corrupted, it will ignore it and move forward. If you really want to try the reapir tool, ensure the data is backed up first and then check for orphan memtable files on disk (those will be copied into separate directory). Note, that repair tool will always ignore column families except the very first one.