Skip to main content
Multilingual TursoDB, MVCC & AI Agent database guides Read Engine Guide →
Turso Database Fundamentals Sync

Checkpoint

How to compact the local WAL to bound disk usage while preserving sync state.

NOTE

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);
before = conn.stats()
print("WAL size before:", before.main_wal_size)

conn.checkpoint()

after = conn.stats()
print("WAL size after:", after.main_wal_size)
before, _ := db.Stats(ctx)
log.Printf("WAL size before: %d", before.MainWalSize)

db.Checkpoint(ctx)

after, _ := db.Stats(ctx)
log.Printf("WAL size after: %d", 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();
conn.checkpoint()
if err := db.Checkpoint(ctx); err != nil {
	return err
}
Synced from official Turso documentation ( tursodatabase/turso-docs · MIT License) Official Docs ↗
Search
Press Esc to close · Powered by Pagefind