Persistent Databases in the Browser with DuckDB-Wasm and OPFS
4 points by eatonphil
4 points by eatonphil
This seems contradictory:
DuckDB uses a write-ahead log. Committed transactions are appended to analytics.duckdb.wal first. The main file is updated at checkpoint time. A checkpoint happens automatically when the WAL grows past checkpoint_threshold (16 MB by default), when the database is closed cleanly, or when you run CHECKPOINT yourself.
…Call CHECKPOINT after writes you cannot afford to lose. The DuckDB documentation is explicit about this: writes are flushed to OPFS by CHECKPOINT.
The first paragraph says a commit writes to the WAL, and a checkpoint just moves changes from the WAL to the main file (just like SQLite.)
The second paragraph contradicts this, saying a checkpoint is necessary for a transaction to be durable.
My best guess is that, since writes occur in a web worker task, the checkpoint operation is overloaded to both ensure any async writes complete, and to move from the WAL to the main file. But this seems too heavyweight; the second step is slow (not the kind of thing you want to do after every operation) and not necessary for durability.