Browse by type
A SQLite VFS that stores databases behind a small gRPC service, so any datastore can hold SQLite databases. Stock SQLite runs on it unchanged, each transaction reaches the server as one atomic commit, and read-only replicas read consistent versions.
Give every user, tenant or agent its own SQLite database, kept in FoundationDB, Postgres, an object store or whatever you already run. Your server stores pages and leases; the VFS handles SQLite's locking, journaling and caching.
[!WARNING] This is early software. A deterministic simulator checks the guarantees below, but gRPSQLite has not run in production.
Commit. A crash at any point leaves the last committed state. See Transactions.ChangedPages call. Every cached page is checked against its checksum before use. See Page cache.Request counts come from the simulator, so they are exact and repeat run to run. Wall times run over gRPC on loopback with 1 ms added to every response, on one Intel Core Ultra 9 285. The database holds 20,000 rows of 200 bytes in 4 KiB pages, and SQLite caches 50 pages.
| Requests | Writer | Writer, page cache | Replica | Replica, page cache |
|---|---|---|---|---|
| Insert 20,000 rows in one transaction | 3 | |||
| 500 point lookups | 478 | 0 | 978 | 500 |
| 50 range scans of 1,000 rows | 398 | 0 | 448 | 50 |
| Full scan | 36 | 0 | 37 | 1 |
| 500 point lookups while a writer commits 50 times | 1,245 | 619 |
| Seconds at 1 ms a request | Writer | Writer, page cache | Replica | Replica, page cache |
|---|---|---|---|---|
| Insert 20,000 rows in one transaction | 0.018 | |||
| 500 point lookups | 1.041 | 0.001 | 2.122 | 1.077 |
| 50 range scans of 1,000 rows | 0.879 | 0.006 | 0.987 | 0.115 |
| Full scan | 0.087 | 0.002 | 0.088 | 0.005 |
Clients without a page cache start cold. Clients with one run each workload once to warm it.
CREATE TABLE and one for the INSERT.ChangedPages call after each commit.ChangedPages. Against a server without it, the cached replica sends as many requests as the uncached one. Each read then carries the cached page's checksum, and the server answers "unchanged" instead of sending the bytes again.cargo run --release -p grpsqlite-sim --bin bench -- --latency-ms 1 reruns both tables.
Linux with Rust, a C compiler, libclang (libclang-dev on Debian and Ubuntu), curl, openssl and unzip. Start the in-memory reference server, then build a SQLite 3.54.1 shell with gRPSQLite as its default VFS:
cargo run --release -p grpsqlite-memory & # listens on 127.0.0.1:50051
scripts/build-sqlite
target/sqlite/sqlite3-grpsqlite main.db
CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO users(name) VALUES ('Alice'), ('Bob');
SELECT * FROM users;
Quit and reopen main.db: the rows live on the server. Open it read-only for a replica:
target/sqlite/sqlite3-grpsqlite -readonly main.db 'SELECT count(*) FROM users'
scripts/smoke runs examples/*.sql against servers with and without atomic commits.
COMMIT succeeds only after the server acknowledges every page of the transaction. A failed COMMIT has an unknown outcome, and the next transaction reads whichever state the server holds.ATTACH, and several databases and connections per process.SQLite reads and writes its files through a VFS. The gRPSQLite VFS keeps each database's state in one place per process, holds its lease, and turns SQLite's file calls into requests:
sequenceDiagram
participant Q as SQLite
participant V as gRPSQLite VFS
participant S as Your server
participant D as Your store
Q->>V: open main.db
V->>S: Open, read-write
S-->>V: session, lease, capabilities
Note over V,S: heartbeats keep the lease alive
Q->>V: read page 1
V->>S: Read
S->>D: get
Q->>V: write pages, spill the cache
V->>V: buffer the transaction in memory
Q->>V: sync, at COMMIT
V->>S: Commit: every page, with the lease
S->>D: one transaction, if the lease is current
S-->>V: the new version
V-->>Q: COMMIT succeeds
Temporary files, statement journals and, on servers with atomic commits, rollback journals stay in client memory. Only the files that must survive a client crash go to the server.
The VFS buffers every write and truncation of the main database from a transaction's first write. Reads inside the transaction see the buffer. At SQLITE_FCNTL_SYNC, which SQLite sends at every commit even with PRAGMA synchronous=OFF, the VFS sends the buffer as one Commit. It discards the buffer when the transaction rolls back, when SQLite drops below a reserved lock, on close, and after an I/O error.
SQLite's own batch-atomic path would do this only in builds with SQLITE_ENABLE_BATCH_ATOMIC_WRITE, and it lets cache spills reach the file early. Owning the boundary makes every build atomic.
The lease holder keeps the database header and file size in memory and updates them from its own commits, so a transaction's first read needs no request.
A read-write open acquires the database's lease, and a background task heartbeats it. The server checks the lease inside the same transaction that applies a commit. When a heartbeat fails, or none succeeds within the lease's TTL, the VFS fails every operation on the database with SQLITE_IOERR and drops its caches until the application reopens it. A reopen acquires the lease again.
Several connections to one database in a process share the lease, and an in-process lock table enforces SQLite's lock levels among them. Rollback journals belong to the session that wrote them, so a connection opened after a lease loss never plays back the broken session's journal over another writer's commits.
A read-only open needs a server with atomic commits and point-in-time reads. Each response carries an opaque version. The first response in a read transaction fixes the version, the VFS sends it with every later read, and SQLite's unlock releases it. Each read also returns the file's size at that version, so a transaction needs no separate size request.
SQLite notices commits through the header's change counter, which every commit through an atomic server updates. Exclusive locking mode stops those updates, so the VFS refuses PRAGMA locking_mode=exclusive on servers with atomic commits; the lease already makes the client the only writer.
With GRPSQLITE_CACHE_DIR and GRPSQLITE_CACHE_MAX_BYTES set, each database caches pages on local disk, one file per page, evicting the least recently used.
ChangedPages call lists what changed, the cache drops those pages, and the transaction reads the rest locally. On servers without ChangedPages, each read sends the cached page's XXH3-64 checksum and the server answers "unchanged" instead of sending the bytes.Every page is checked against its checksum before use, so a damaged cache costs a request, never a wrong answer. A lock file keeps two processes from sharing one database's cache; the second runs without one.
Without atomic_commit, SQLite's own crash recovery protects transactions. The rollback journal or WAL lives on the server, each Write applies alone, and after a crash the next writer replays the journal. Use journal_mode=delete, truncate or persist, or WAL with exclusive locking, set before the first read:
PRAGMA locking_mode=exclusive;
PRAGMA journal_mode=wal;
The VFS has no shared memory, so in normal locking mode SQLite keeps the database out of WAL, and a connection that opens a WAL database without exclusive locking fails with SQLITE_CANTOPEN.
SQLite treats a failed WAL write as one that never happened, yet the frames may have reached the server and completed a commit. After a failed WAL write, the VFS fails every operation until the database reopens, and the reopen rebuilds SQLite's WAL index from the server.
A transaction that writes several attached databases needs a server with atomic commits: SQLite's super-journal would otherwise live in client memory, and a crash would lose it.
The VFS is the grpsqlite crate in crates/vfs.
Linked into SQLite. cargo build --release -p grpsqlite --features static builds target/release/libgrpsqlite.a. Compile SQLite with -DSQLITE_EXTRA_INIT=grpsqlite_extra_init and link the library: SQLite then registers gRPSQLite as its default VFS while it initializes. scripts/build-sqlite does this for the shell.
Loaded at runtime. cargo build --release -p grpsqlite --features dynamic builds target/release/libgrpsqlite.so. Loading it registers gRPSQLite as the default VFS:
.load target/release/libgrpsqlite
From Rust. With the static feature, grpsqlite::register_static registers a Core under any name, next to SQLite's own VFSes. Core takes any Backend; GrpcBackend is the gRPC client. crates/sim/src/harness.rs shows the pattern with rusqlite.
| Variable | Default | Meaning |
|---|---|---|
GRPSQLITE_URL |
http://localhost:50051 |
The server. |
GRPSQLITE_CLIENT_TOKEN |
empty | Sent with every Open. |
GRPSQLITE_CONNECT_TIMEOUT_MS |
10000 |
Connection timeout. |
GRPSQLITE_RPC_TIMEOUT_MS |
30000 |
Deadline for each request. |
GRPSQLITE_KEEPALIVE_INTERVAL_MS |
10000 |
HTTP/2 keepalive interval. |
GRPSQLITE_KEEPALIVE_TIMEOUT_MS |
20000 |
HTTP/2 keepalive timeout. |
GRPSQLITE_CACHE_DIR |
unset | Local page cache directory; set with GRPSQLITE_CACHE_MAX_BYTES. |
GRPSQLITE_CACHE_MAX_BYTES |
unset | Most bytes each open database may cache. |
GRPSQLITE_LOG |
warn |
off, error, warn, info, debug or trace, sent to sqlite3_log. |
An invalid setting makes every open fail with SQLITE_CANTOPEN and logs the reason; the host process keeps running. The VFS connects on the first open, so a missing server fails that open rather than the process.
A server declares what it supports in its Open response.
| Capability | Set it when your store can | What
browse all types & interfaces →
$ claude mcp add gRPSQLite \
-- python -m otcore.mcp_server <graph>