Postgres-wasm is a project in which PostgreSQL has been ported to WebAssembly
Recently, free access to postgres-wasm was announced . This is a PostgreSQL server that runs in a browser and offers a full set of features, including browser state persistence, restoration from pg_dump, and logical replication from a remote database.
Postgres-wasm is an open-source project that has ported PostgreSQL to WebAssembly . This solution was developed through a collaboration between Supabase, a cloud database provider, and Snaplet, a company specializing in database programming.
“Today we are launching postgres-wasm with our friends at Snaplet,” said Supabase Engineer Mark Burggraf
For those unfamiliar with Postgres, it 's one of the most advanced open-source database management systems . It's feature-rich, with robust data types, powerful indexing, and a wide range of built-in functions that can be used to simplify the data stack and allow developers to focus on building their application. Postgres is more than just a relational database; it has become your trusted data platform.
About Postgres-wasm
Supabase isn't the first to get Postgres running in a browser; that title belongs to the Crunchy Data team, who shared their version on HN a month ago. In their desire to develop an open-source version of Crunchy Data's proprietary version, Supabase partnered with Snaplet to build Postgres-wasm.
Thanks to Postgres-wasm, PostgreSQL can be run directly through a web browser. This was achieved using the Linux distribution Buildroot, characterized by its extremely small size, and the v86 emulator that allows replicating the operation of an x86 terminal.
WebAssembly, on the other hand , is intended to allow the construction of high-performance applications on web pages, but it doesn't make web-specific assumptions or provide web-specific functionality, so it can also be used in other environments. It's an open standard that aims to support any language on any operating system, and in practice, all the most popular languages already have at least some level of support. Supabase uses v86 to run its VM within the browser.
Running Postgres in a browser is great , but connecting to it with PgAdmin is even better. Unfortunately, browsers block access to the VM's TCP network. To circumvent this, Supabase routes traffic through WebSockets. They use a WebSockProxy fork that allows the emulator to communicate with the internet by converting data sent through a WebSocket port into TCP packets. The WebSockProxy fork adds the ability to tunnel the Postgres server.
Among the project's key features are the following:
- Postgres 14.5, psql, pg_dump, etc.
- Save and restore state to/from a file.
- Save and restore Postgres state to/from browser storage (IndexedDB).
- Quick boot from a status file or full emulator reset.
- Memory configuration options from 128 MB to 1024 MB.
- Set the font size for the terminal.
- Upload files to the emulator (including CSV and database dumps).
- Download emulator files.
- Outgoing network connectivity from the emulator to the Internet.
- Inbound network tunnel to postgres port 5432 inside the emulator.
In general, the entire project is contained in a single snapshot of size 12 MB with which to run a PostgreSQL server.
As Postgres-wasm developers admit, the runtime performance is not very high, but in itself the goal of making PostgreSQL 14.5 usable from a full browser with a psql command line interface has been successfully achieved. .
Finally, if you are interested in learning more about this , you can find the details at the following link.