RocksDB-Sharp

DbOptions

DbOptions carries database-wide settings. It is the first argument to every RocksDb.Open* overload. Settings here apply to all column families in the database.

Most of these mirror knobs in the upstream include/rocksdb/options.h — read the Setup Options and Basic Tuning wiki page for the rationale and recommended values.

var options = new DbOptions()
    .SetCreateIfMissing(true)
    .SetCreateMissingColumnFamilies(true)
    .IncreaseParallelism(Environment.ProcessorCount)
    .SetMaxBackgroundCompactions(4)
    .SetMaxBackgroundFlushes(2)
    .SetMaxOpenFiles(-1);

Lifecycle and creation

Setter Default Notes
SetCreateIfMissing(bool) false Create the DB if the directory doesn't exist.
SetCreateMissingColumnFamilies(bool) false Auto-create any column family missing at open time.
SetErrorIfExists(bool) false Fail open if the DB already exists.
SetParanoidChecks(bool) true Aggressively validate on read.
new DbOptions().SetCreateIfMissing(true).SetCreateMissingColumnFamilies(true);

Parallelism and background work

IncreaseParallelism(n) is the one-liner shortcut that bumps the number of background compaction and flush threads at once. It's the recommended starting point for any non-tiny workload.

new DbOptions().IncreaseParallelism(Environment.ProcessorCount);

Finer-grained knobs:

  • SetMaxBackgroundCompactions(int) — concurrent compactions.
  • SetMaxBackgroundFlushes(int) — concurrent memtable flushes.

Upstream reference: Compaction wiki.


Files, memory, and the WAL

Setter What it does
SetMaxOpenFiles(int) Cap on simultaneously open SST files. -1 keeps them all open.
SetMaxFileOpeningThreads(int) Used when MaxOpenFiles == -1 and the DB opens.
SetMaxTotalWalSize(ulong) When WALs exceed this, the oldest backing CF is forced to flush.
SetWalDir(string) Put WAL on a separate (often faster) volume.
SetWalTtlSeconds(ulong) / SetWalSizeLimitMB(ulong) How long old WAL files are retained — required for WAL replication.
SetWalRecoveryMode(Recovery) Behaviour on recovery from a corrupt WAL.
SetWalCompression(Compression) Compress WAL records (e.g. Compression.Zstd).

Upstream reference: Write-Ahead Log, Replication / Recovery.

new DbOptions()
    .SetWalDir("/fast-ssd/myapp/wal")
    .SetWalTtlSeconds(60)
    .SetMaxTotalWalSize(1024UL * 1024 * 1024);   // 1 GiB

Statistics and logging

var opts = new DbOptions().EnableStatistics();

// later:
string s = opts.GetStatisticsString();
  • SetDbLogDir(string) — separate directory for the LOG file.
  • SetKeepLogFileNum(ulong) — log rotation count.
  • SkipStatsUpdateOnOpen(bool) — speeds up open on slow disks.

Convenience setters

Setter Tuning shortcut
IncreaseParallelism(int) Background threads.
OptimizeLevelStyleCompaction(ulong) Level-style compaction defaults.
OptimizeUniversalStyleCompaction(ulong) Universal-style compaction defaults.
new DbOptions()
    .OptimizeLevelStyleCompaction(memtableMemoryBudget: 512UL * 1024 * 1024);

Inspecting at runtime

DbOptions doesn't store every value as a managed property — most flow straight to native memory. Use the database's GetProperty once open to read effective state:

db.GetProperty("rocksdb.options-statistics");
db.GetProperty("rocksdb.stats");
db.GetProperty("rocksdb.estimate-num-keys");

See the GetProperty wiki for the full list.


See also

Referenced by

© 2026 RocksDB-Sharp. All rights reserved.