PostgreSQL in the Browser

The ZeroFS Web UI terminal boots a Linux VM inside the browser and mounts ZeroFS as its root filesystem. The VM gets POSIX semantics over 9P, 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 before reaching S3:

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.

Why it works

The Web UI terminal uses v86, a JavaScript x86 emulator that runs a Linux kernel in the browser. The guest kernel has 9P support compiled in 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. Place the PostgreSQL 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 immediately.

# From another machine or the file manager, copy a static 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, a mail server — runs the same way: booted in a browser tab, with its data persisted to S3.


Next Steps

Was this page helpful?