Skip to main content
This particular usage uses the Turso Cloud to sync the local Turso databases and assumes that you have an account.

Overview

The sync engine uses a WAL (Write-Ahead Log) to track local writes. Over time, the WAL grows as you make changes. Checkpoint compacts it by transferring committed frames into the main database file and then truncating the WAL. Auto-checkpoint is disabled for sync databases — you must call checkpoint() explicitly.

Why Checkpoint Matters

Without checkpointing, the WAL grows unbounded. After many writes, the WAL can become significantly larger than the database itself. Checkpointing reclaims that disk space. You can observe this with stats():
const before = await db.stats();
console.log('WAL size before:', before.mainWalSize);

await db.checkpoint();

const after = await db.stats();
console.log('WAL size after:', after.mainWalSize);

When to Checkpoint

Call checkpoint() periodically based on your write patterns:
  • After bulk inserts — if you insert many rows at once, checkpoint afterward to reclaim WAL space
  • On a schedule — for steady write workloads, checkpoint at regular intervals (e.g. every few minutes)
  • When WAL size is large — use stats().mainWalSize to monitor and checkpoint when it exceeds a threshold
await db.checkpoint();