NusaDB

Relational SQL on one machine, from the wire protocol down to the 8 KiB page.

One server binary, written in Rust. Rows live in the leaves of a clustered B+tree, COMMIT returns once a checksummed redo log is on disk, and drivers in eight languages speak its own wire protocol.

or run the container image
$ docker run -d --name nusadb -p 5678:5678 \
    -v nusadb-data:/var/lib/nusadb \
    -e NUSADB_USER=app \
    -e NUSADB_PASSWORD=change-me \
    nusadb/nusadb:0.1.0-beta.16
Write skew, refused at commit two nusadb-cli sessions, SERIALIZABLE
session 1session 2
begin
nusa> BEGIN
  ...> ISOLATION LEVEL SERIALIZABLE;
BEGIN
nusa> BEGIN
  ...> ISOLATION LEVEL SERIALIZABLE;
BEGIN
read
nusa> SELECT count(*) FROM oncall
  ...> WHERE on_shift;
count
-----
2
SELECT 1
nusa> SELECT count(*) FROM oncall
  ...> WHERE on_shift;
count
-----
2
SELECT 1
write
nusa> UPDATE oncall SET on_shift = false
  ...> WHERE doctor = 'ana';
UPDATE 1
nusa> UPDATE oncall SET on_shift = false
  ...> WHERE doctor = 'budi';
UPDATE 1
commit
nusa> COMMIT;
COMMIT
nusa> COMMIT;
ERROR 40001: serialization conflict; transaction TxnId(7) must retry
Two doctors start on shift. Each session sees two and takes one off; the second COMMIT is refused, so one stays on call. In each row session 1 ran first. Output unedited apart from the connection banner. Retrying a 40001
Fit

One server, one disk, one SQL database you can reason about

For applications on a single host that want ordinary relational guarantees from it. It is not a cluster, so the second list matters as much as the first.

Limits and capacity, in full

Fits today

  • An application database on one host, with SERIALIZABLE available per transaction when a race would be expensive.
  • Data larger than memory. Table and index pages are cached, evicted and spilled under --max-resident-bytes.
  • Reporting next to transactions: window functions, recursive CTEs, grouping sets, and sorts, joins and aggregates that spill to disk instead of failing.
  • Search without another service: full-text in the simple, english and indonesian configurations, and VECTOR(n) with an HNSW index.
  • Operators who want encryption at rest, scheduled backups and point-in-time restore from flags on the server binary.

Does not fit yet

  • Failover without a person. There is no clustering. A read-only standby follows the primary and is promoted by restarting it without --standby-from.
  • A standby that must trail by seconds. Log segments reach the archive when the primary checkpoints, so the standby lags by that cadence.
  • Tools that speak another database's protocol. NusaDB has its own; use one of the eight drivers or nusadb-cli.
  • Vector indexes larger than RAM. HNSW graphs are held in memory whatever the page-cache bound.
  • Named time zones and locale collations. SET TIME ZONE takes UTC or a fixed offset, and text compares by bytes.
Write path

A commit is durable at the fsync. A checkpoint folds the log away.

Changed pages stay in the page cache and reach disk only through a checkpoint, which writes just those pages to a new immutable segment. Watch two transactions go through.

Fig. 1  Write path of one database directory 2 transactions committed, checkpoint pending
btree.wal redo log, append-only page cache 8 KiB pages in memory btree.wal.pages/ immutable segments btree.wal.ckpt checkpoint image frame: lsn u64 · len u32 · crc32 · body lsnlencrcinsert lsn 1201 · txn 7 lsnlencrcinsert lsn 1202 · txn 7 lsnlencrccommit lsn 1203 · txn 7 lsnlencrcupdate lsn 1204 · txn 8 lsnlencrccommit lsn 1205 · txn 8 fsync: txn 7 durable fsync: txn 8 p0p2p6p9p11 changed since last checkpoint clean: may be evicted (clock) a full cache spills changed pages to btree.wal.spill; recovery never reads it …620069-…-full.seg every live page ….seg next .seg CHECKPOINT writes changed pages only; past 32 segments, or dead pages over 2 × live + 1024, it writes a -full one header segment names page → segment, slot, crc32 logical records covers lsn 1200 restart replays the log after this lsn
Fig. 1Records are buffered and written with the commit, whose fsync is the durability point. Changed pages stay in the page cache; table pages reach disk only through a checkpoint, which copies them into a new segment, publishes an image naming every live page, and truncates the log to zero bytes. On restart the engine opens the image, loads pages as queries touch them, and replays only the log written after it.
Storage

The row is in the leaf.

Tables are clustered B-link trees keyed by a row id the engine assigns, so a lookup ends at the leaf that holds the row, with no second hop into a separate heap. A reader that arrives during a split follows the right link instead of starting over.

Fig. 2  Leaf page, little-endianbyte offsets above the cells; widths not to scale
0191719 kindu8 right_linku64 page id high_keyu64, exclusive countu16 entry 0sorted by row_id entry 1 entry … free space one page = 8,192 bytes +0+8+10+18+26+34 row_idu64, engine-assigned lenu16 xmincreating txn xmaxdeleting txn, 0 = live undoprevious version tuple bytesencoded by the SQL layer version header, 24 bytes high bit of len set: overflow stub, header inline
Fig. 2A leaf entry is the newest version of one row. Its 24-byte header decides visibility. A row too large for a leaf keeps a stub whose first 24 bytes are that header, with the rest in a chain of overflow pages, so a visibility check never reads the chain. Interior pages hold fixed 16-byte separator and child pairs.
Durability

Each log record carries its position, its length and a CRC over both.

The log is the durable copy of every change since the last checkpoint. Because the CRC32 covers the 16-byte header as well as the body, a zeroed sector or a corrupted length is caught, and a torn record at the end of the file ends the durable prefix cleanly.

Fig. 3  Log framebtree.wal
081216 lsnu64, log position lenu32, body bytes crc32of lsn, len, body bodyone record: insert, update, delete, commit, DDL, sequence, prepare … covered by the crccovered by the crc plain kind u8 payloadstored as is up to 64 bytes, lz4 above that --encryption-key-file nonce12 bytes AES-256-GCM-SIV ciphertextof kind + payload; aad = lsn tag16 bytes
Fig. 3Compress, then encrypt, then checksum. With encryption on, a torn tail is still recognised without the key, and a frame whose CRC is intact but whose tag fails cannot come from a crash, so recovery refuses the log at that point instead of truncating it.
64 MiBlog size at which the background worker checkpoints a database (--checkpoint-threshold-bytes)
5 show often the worker checks each log (--checkpoint-interval)
2 slongest it holds new transactions to find a quiet moment (--checkpoint-max-pause)
2 passesat recovery: collect the committed transactions, then re-apply only their operations, in log order

What kill -9 leaves behind

This session ran on the same server as the examples above. A checkpoint folds a 40 MB log into one full segment and truncates the log. An update of 100 rows adds a 32 KiB incremental segment at the next checkpoint. A row committed after the last checkpoint exists only in a 224-byte log when the server is killed with SIGKILL, and it is there after the restart.

Listings trimmed to size and name, and the shell's --host flag left out. Id 8 went to a transaction that never committed; identity values are not handed back on rollback. Other ways to keep a copy: scheduled hard-link backups, a log archive with point-in-time restore, and a read-only standby that follows the archive.

shell, data directory of database nusadb
$ cd data && ls -l base/nusadb
-rw-r--r--  40529022  btree.wal
-rw-r--r--        45  btree.wal.format
-rw-r--r--         0  btree.wal.lock
-rw-r--r--         5  engine
$ nusadb-cli -c "CHECKPOINT;"
CHECKPOINT
$ ls -l base/nusadb base/nusadb/btree.wal.pages
-rw-r--r--         0  btree.wal
-rw-r--r--    252931  btree.wal.ckpt
-rw-r--r--        45  btree.wal.format
-rw-r--r--         0  btree.wal.lock
drwxr-xr-x            btree.wal.pages
-rw-r--r--         5  engine
-rw-r--r-- 100818944  00000000000000620069-18e3035d61f09521-full.seg
$ nusadb-cli -c "UPDATE invoices SET amount = amount + 1 WHERE id <= 100; CHECKPOINT;"
UPDATE 100
CHECKPOINT
$ ls -l base/nusadb/btree.wal.pages
-rw-r--r-- 100818944  00000000000000620069-18e3035d61f09521-full.seg
-rw-r--r--     32768  00000000000000620174-18e303603e38c911.seg
# ... more statements from the examples above ...
$ nusadb-cli -c "CHECKPOINT;"
CHECKPOINT
$ nusadb-cli -c "INSERT INTO orders (region, total, placed) VALUES ('south', 12.50, '2026-10-29');"
INSERT 1
$ ls -l base/nusadb/btree.wal
-rw-r--r--       224  btree.wal
$ pkill -9 nusadb-server
$ nusadb-server --listen 127.0.0.1:47391 --data-dir . &
$ nusadb-cli -c "SELECT id, region, total FROM orders WHERE id >= 6;"
id | region | total
---+--------+------
6  | south  | 42.00
7  | south  | 9.99
9  | south  | 12.50
SELECT 3
Architecture

Seven layers, one dependency direction

The storage side never imports the SQL side. They meet at one Rust trait, so each half can be tested on its own. Storage code is also exercised against simulated disks that tear writes, fail fsync and lose power, replayable from a single seed.

Fig. 4  Crates by layer
Clientnusadb-cli · 8 drivers · C API Protocolnusadb-wire · TLS 1.3 · SCRAM SQL enginenusadb-sql · parse, plan, execute StorageEngine trait (nusadb-core) Transactionsnusadb-btree · MVCC, SSI Storagenusadb-btree · B-link tree, cache Lognusadb-wal · CRC32, lz4, AEAD Filesbase/<db>/ · global/ query COMMIT · fsync · ok
Fig. 4Crate names as they appear in the source tree. Rows travel as opaque bytes across the trait; the SQL layer owns their encoding.
  1. Client

    nusadb-cli with aligned, expanded, CSV and JSON output, drivers for Rust, Java, Node.js, Python, Go, Ruby, PHP and .NET, and a C API.

  2. Protocol

    Length-prefixed frames on one port. TLS 1.3 through rustls, mutual TLS with --tls-client-ca, SCRAM-SHA-256, extended query with named statements and portals, COPY in text and binary, notices.

  3. SQL engine

    Parser, analyzer, a cost-based planner that reads histograms and most-common values, and a vectorized executor working on 1,024-row batches with AVX2 kernels and a portable fallback.

  4. Transactions

    Snapshots from version stamps, no-wait row locks, serializable snapshot isolation tracked per row, savepoints, two-phase commit, deferrable constraints.

  5. Storage

    Clustered B-link tables, B+tree indexes in pages too, a page cache with clock eviction and spill, HNSW graphs for vectors, and a background purge of dead versions.

  6. Log

    Redo records with CRC32 and lz4, optionally sealed, a commit that returns after fsync, incremental checkpoints over immutable segments, and an optional archive for point-in-time restore.

  7. Files

    One directory per database under base/, a cluster catalog under global/, and a lock file that keeps a second server off the same directory.

Operating

Everything is a flag on nusadb-server

There is no configuration file and no second daemon. These are the flags most deployments touch, with their defaults from --help. The full list of 44 is in configuration.

FlagDefaultWhat it does
Memory
--mem-budget0 (detect)Total budget; on Linux, the smaller of host RAM and the cgroup limit. Work memory, the page-cache bound and spill to <data-dir>/tmp follow from it.
--max-resident-bytesderivedPage-cache bound per database. Clean pages are evicted, changed pages spill.
--work-memderivedPer-stage budget for sorts, hash joins, aggregates and windows before they spill.
Security
--auth-user USER:PWnoneTurns on SCRAM-SHA-256 for every connection. Without it the server trusts all clients and logs a warning.
--tls-cert, --tls-keynoneTLS 1.3 on the same port. Add --tls-client-ca to require client certificates.
--encryption-key-filenoneSeals the log, checkpoint image, segments, spill files, archive and backups with AES-256-GCM-SIV under a per-database data key.
Copies
--backup-dirnoneHard-link backups every --backup-interval (86400 s), keeping --backup-keep (7).
--wal-archive-dirnoneArchives each checkpoint's log segment and image, for --restore-to-time or --restore-to-lsn.
--standby-fromnoneRuns a read-only standby that follows a primary's archive.
Connections
--max-connections25Extra connections queue; --reject-excess-connections refuses them with 53300 instead.
--statement-timeout0 (off)Cancels a statement after this many seconds with 57014.
--metrics-listennoneServes metrics in Prometheus text format on a separate address.
Measurements

Numbers, with the machine and the build they came from

Single-machine measurements on a laptop, not a tuned benchmark. Each was taken on an earlier 0.1.0 build named next to it, and none has been repeated on beta.16. They show orders of magnitude, not a ceiling.

ResultWhat was measured
0.1 msMedian and 95th-percentile primary-key lookup, 1,000 lookups on a 100,000-row table, Python driver over TCP loopback, one connection.2026-09-26 · build 9793cb5
2.7 msSELECT count(*) over the same 100,000 rows, as a non-superuser role.2026-09-26 · build 9793cb5
713 msUPDATE … SET v = v + 1 on all 100,000 rows in one statement.2026-09-26 · build 9793cb5
0.25–0.28 msRange filter with ORDER BY k LIMIT 20 on 500,000 rows after ANALYZE; the plan reads the index in order and stops at the limit. Best of five after a warm-up.2026-09-27 · build c37b16f
0.27–0.29 sServer start to first query answered, 600,000 rows of 400 random bytes with a primary key, 296 MB checkpoint image.2026-09-27 · build 259200c
64 MBResident memory during a full scan of those 600,000 rows with the page cache bounded at 64 MB (engine probe, 140 ms). Opening the engine took 4 ms.2026-09-27 · build 259200c
33/33, 26/26Driver checks passed by the published Python 0.1.2 and Rust 0.1.2 packages against a release server.2026-10-14 · build 0437b3e

Cost of encryption at rest

200,000 rows of 200 bytes, transactions of 1,000 rows, median of three runs. Each pair of bars has its own scale.

  • unencrypted
  • encrypted
bulk insert 1.42 s 1.51 s checkpoint 41 ms 51 ms reopen 3.5 ms 3.6 ms scan, cold cache 24 ms 42 ms
Cost of encryption at rest, median of three runs
OperationUnencryptedEncrypted
Bulk insert1.42 s1.51 s
Checkpoint41 ms51 ms
Reopen3.5 ms3.6 ms
Scan, cold cache24 ms42 ms

A sealed page takes 8,220 bytes instead of 8,192, and a log record 28 bytes more. Pages already in the cache cost nothing extra.

Hardware: an Apple Silicon MacBook Pro, macOS (Darwin 25.5), local disk, no container, release builds. The encryption figures are from the engine's own architecture notes (2026-10-14, Apple M-series laptop).

Measurements over the wire include the round trip through the Python driver on loopback. The engine probe runs in process.

Drivers

Eight languages, no native dependencies

Every driver speaks the protocol directly and binds parameters as $1, $2. Typed columns come back as the language's own types: integers, decimals, datetimes, parsed JSON.

Python PyPI 0.1.2

Install
pip install nusadb
Extras
[sqlalchemy] [asyncio] [django]
URL
nusadb://user:pw@host:5678/db
API
DB-API 2.0, asyncio
python
import nusadb

conn = nusadb.connect(host="127.0.0.1", port=5678, user="app",
                      password="change-me", database="nusadb")
cur = conn.cursor()
cur.execute("SELECT id, region FROM orders WHERE total > $1", [100])
for row in cur:
    print(row)
conn.close()

Connection settings, TLS, pooling and notifications

Install

Three ways to get a server running

Container image

nusadb/nusadb:0.1.0-beta.16 for linux/amd64 and linux/arm64, with the server and the shell. The data directory is /var/lib/nusadb.

shell
docker run -d --name nusadb \
  -p 5678:5678 \
  -v nusadb-data:/var/lib/nusadb \
  -e NUSADB_USER=app \
  -e NUSADB_PASSWORD=change-me \
  nusadb/nusadb:0.1.0-beta.16

docker exec -it nusadb nusadb-cli --user app

From source

Rust 1.95 is pinned in the repository and rustup fetches it. The first build takes a few minutes. This is the way to run beta.16 outside a container.

shell
git clone https://github.com/nusadb/nusadb.git
cd nusadb
cargo build --release
./target/release/nusadb-server \
  --listen 127.0.0.1:5678 \
  --data-dir ./data \
  --auth-user app:change-me

Release archives

Prebuilt nusadb-server and nusadb-cli for Linux (x86-64, ARM64), macOS (Intel, Apple Silicon) and Windows (x86-64). The newest archives on GitHub are for 0.1.0-beta.14.

shell
# TARGET: x86_64-unknown-linux-gnu,
# aarch64-apple-darwin, ...
tar xzf nusadb-v0.1.0-beta.14-$TARGET.tar.gz
cd nusadb-v0.1.0-beta.14-$TARGET
./nusadb-server --data-dir ./data \
  --auth-user app:change-me

GitHub releases

FAQ

Questions people ask first

Can I connect with a client written for another database?

No. NusaDB has its own wire protocol, and a client that sends another engine's handshake gets no answer, so it looks like a connection that hangs. Use nusadb-cli, one of the eight drivers, or write a client against the protocol specification. SQL written for other engines usually runs unchanged.

What happens on a crash?

Every transaction whose COMMIT returned is there after restart, and nothing of one that had not. The engine opens the last checkpoint image, loads pages from its segments as they are used, and replays the log written after it. Restart time grows with the log written since the last checkpoint, not with the size of the data.

Why did my transaction fail with 40001?

Locks do not wait. When two transactions write the same row, or a serializable transaction would see a result no serial order could produce, one of them fails with 40001 and should be retried. A single autocommit statement is retried by the server, up to max_autocommit_retries attempts (50 by default). Explicit transactions need a retry loop in the application; the transactions page has one in several languages.

Does my data have to fit in memory?

Table pages and B-tree index pages do not. They are loaded from segments on first use, evicted when clean and spilled when changed. Index entries larger than about 2 KB, notes for index entries awaiting purge, and HNSW vector graphs stay in memory. When those reach the bound, the next insert or update fails with an out-of-memory error rather than the process growing until the host kills it.

How do I back up a running server?

A checkpoint image with the segments it names is a consistent copy of one database, taken while the server keeps writing. --backup-dir takes hard-link snapshots of them on a schedule. For point-in-time restore, add --wal-archive-dir and rebuild offline with --restore-database and --restore-to-time. Copying backups off the machine is up to you.

Is it ready for production?

It is a pre-1.0 beta. The storage format is versioned and a newer release upgrades an older data directory in place, but interfaces can still change between releases, and the features on the limits page are not built. Read that page before deciding.

Which SQL does it accept?

Most of standard SQL that makes sense on one node: joins of every kind, subqueries, CTEs including recursive ones, window functions, grouping sets, MERGE, ON CONFLICT, triggers, SQL and NusaScript routines, views and materialized views, partitioned tables, sequences, and a wide type system. The statement index lists each statement with an example, and not accepted lists what is refused.

Start a server, open the shell, and read the plan it prints.