PostgreSQL in the Browser

The ZeroFS Web UI terminal boots a Linux VM inside the browser (a minimal BusyBox initramfs) and mounts ZeroFS at /mnt over 9P. The mount gets POSIX semantics, so PostgreSQL can run inside it with its data directory on S3.

This is a demonstration, not a deployment recommendation.


The chain

A write from PostgreSQL passes through each of these layers on its way to S3. ZeroFS is the last stop before the object store; it batches writes into immutable segment objects rather than forwarding each one:

psql → PostgreSQL → Linux kernel → virtio-9p → v86 → WebSocket → ZeroFS → S3

PostgreSQL sees a local filesystem. The Linux kernel sees a 9P fileserver. ZeroFS sees an ordinary 9P client.

The write acknowledgment does not wait on S3. ZeroFS compresses and encrypts each 32 KiB extent into a frame inside an in-RAM segment buffer; the buffer is uploaded as one immutable segment object when it reaches 256 MiB or when an fsync forces a seal. PostgreSQL's own fsync of its WAL arrives as a 9P Tfsync, which seals and uploads the open segment before returning (see Durability & Consistency).

Why it works

The Web UI terminal uses v86, a JavaScript x86 emulator that runs a Linux kernel in the browser. The guest loads the 9P kernel modules from its initramfs and mounts a virtio-9p device that v86 bridges over a WebSocket back to ZeroFS. On the ZeroFS side, the WebSocket terminates at the same NinePHandler that serves TCP clients.

There is no reduced mode for browser connections. The transactional code path described in the durability documentation handles every 9P session, whether the bytes arrived over TCP from a mount -t 9p command or over a WebSocket from the emulator.

Try it

Enable the Web UI in your ZeroFS configuration:

[servers.webui]
addresses = ["127.0.0.1:8080"]
uid = 1000
gid = 1000

Start ZeroFS, open http://127.0.0.1:8080, and switch to the terminal tab. The VM boots in a few seconds and drops you into a shell at /mnt.

The VM ships with BusyBox; it does not include PostgreSQL. The v86 guest is a 32-bit x86 machine, so PostgreSQL must be a static 32-bit x86 (i386) build. Place the binaries on the ZeroFS filesystem from any other client (NFS, 9P, or the Web UI file manager). Since /mnt is your S3 bucket, anything you put there is visible to the VM; the guest mounts with cache=loose, so a just-added file may need a moment or a fresh directory listing to appear.

# From another machine or the file manager, copy a static 32-bit x86
# (i386) PostgreSQL build onto the ZeroFS filesystem, e.g. into /postgres

# Then from the terminal tab:
export PATH=/mnt/postgres/bin:$PATH
export LD_LIBRARY_PATH=/mnt/postgres/lib

initdb -D /mnt/pgdata
pg_ctl -D /mnt/pgdata -l /mnt/pgdata/logfile start
psql -d postgres
CREATE TABLE notes (id serial, body text);
INSERT INTO notes (body) VALUES ('written from a browser tab');
SELECT * FROM notes;

The data is in S3. Close the tab, reopen it, start PostgreSQL again, and the rows are still there.

What this opens up

A 128 MB VM inside a JavaScript x86 emulator is not a replacement for a database server; emulation keeps the performance ceiling low.

PostgreSQL is one example. Anything else that assumes a POSIX filesystem, a compiler or a mail server, runs the same way: booted in a browser tab, with its data persisted to S3.


Next Steps

Was this page helpful?