SupabaseburggrafExplainer
Postgres WASM by Snaplet and Supabase
Summary
Supabase and Snaplet open-sourced postgres-wasm, a PostgreSQL server that runs inside a browser and supports browser persistence, pg_dump restoration, and logical replication with a remote database. Rather than compiling PostgreSQL directly to WebAssembly, the project packages a stripped-down Linux image with PostgreSQL in a Buildroot-based virtual machine, then runs it through v86 in the browser. PostgreSQL 14 startup failures were resolved by disabling v86 JIT compilation, while image optimization used a compressed 9P filesystem, asynchronous HTTPS loading, and page_poison=on to produce an initial state of about 12MB. Websocket proxying provides outbound connectivity and a forked proxy with nginx tunnels incoming connections to PostgreSQL. The project remains experimental because the download is currently about 30MB, but the post identifies offline data, testing, development environments, snapshots, and support as potential uses.
Context
The project was open sourced because the authors wanted an open source version of PostgreSQL running in the browser. The current download is about 30MB, so it is not well suited to general use yet, although the post describes potential applications including offline data, testing, development environments, snapshots, and support.
Approach / What changed
The implementation uses a stripped-down Buildroot Linux virtual machine with PostgreSQL, runs that machine in the browser through the v86 x86 emulator, and uses a plain web application as its interface. A compressed 9P filesystem, asynchronous HTTPS loading, and the page_poison=on kernel parameter reduce the initial image. Websocket proxying converts VM traffic into TCP/IP connectivity, while a fork with nginx supports incoming tunnels to PostgreSQL. Browser-to-emulator commands are handled through uploaded shell scripts in an inbox folder.
Takeaways
PostgreSQL 14 failed during initialization with segmentation faults until v86 JIT compilation was disabled; switching PostgreSQL from POSIX to System V memory management also resolved the issue with the current v86 release.
The optimized compressed initial state is about 12MB and includes a running network state, PostgreSQL 14.4, and psql; caching that state makes subsequent refreshes feel almost instant.
Websocket proxying supports outbound traffic and database imports, while the forked proxy maps incoming connections to browser-hosted PostgreSQL instances for tools such as PgAdmin4.
Source and freshness
- Source
- supabase.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.