Lurker News
Hey, Sam and the team from ElectricSQL here.

PGlite is a WASM Postgres build packaged into a TypeScript/JavaScript client library, that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It's 3mb Gzipped, now has support for many Postgres extensions, including pgvector, and it has a reactive "live query" API. It's also fast, with CRUD style queries executing in under 0.3 ms, and larger, multi-row select queries occurring within a fraction of a single frame.
PGlite started as an experimental project we shared on X, and the response to it was incredible, encouraging us to see how far we could take it. Since then we have been working to get it to a point where people can use it to build real things. We are incredibly excited as today, with the release of v0.2, the Supabase team has released the amazing http://postgres.new site built on top of it. Working with them to deliver both PGlite and postgres.new has been a joy.
- https://pglite.dev - PGlite website
- https://github.com/electric-sql/pglite - GitHub repo
- https://pglite.dev/docs - Docs on how to use PGlite
- https://pglite.dev/extensions - Extensions catalog
- https://pglite.dev/benchmarks - Early micro-benchmarks
- https://pglite.dev/repl - An online REPL so that you can try it in the browser
We would love you to try it out, and we will be around to answer any questions.

Comments (108) 37 threads

Earlier comments
saurik1 reply#
Does there happen to be a native analog to this? So like, if I eventually want some kind of native app, I wouldn't have to throw away the architecture entirely and start over? I only see mention of the WASM version of this in the website/docs.
samwillis1 reply#
It's planned.

We want to extract the core changes to Postgres that we had to make and create a "libpglite" C lib that can be linked to from any language/platform.
Support important for React Native, as it doesn't have WASM support.

nikki93#
This would be nice also to have an API that's usable from C/C++ code running in Wasm. I see libraries often do this where they expose a C/C++ library like Postgres to Wasm and the main / documented API is JS and you have to dig a bit to find the C/C++ API if it's possible to access it that way.
ZitchDog1 reply#
> it has a reactive "live query" API

Very cool! Most of the examples for reactive queries are very basic (only single tables). Do live queries support joins / aggregations?

samwillis3 replies#
Yes, they should all work.

We save the query as a view and then introspect it to see what tables it depends on. It then uses pg_notify to watch for changes.
The plan is to integrate pg_ivm (https://github.com/sraoss/pg_ivm) to make it even more efficient.

cheema33#
The existing list of extensions is already quite impressive. But addition of pg_ivm would really take it to the next level.
ZitchDog#
Cool!! Is this available outside of pglite or does it require it for some reason? I could see this being very widely useful.
netghost#
Oh! That's really clever. The live queries make this a very compelling tool for some form of local first development.
herpdyderp1 reply#
What's the equivalent Postgres version? Meaning, if I wanted to make sure my app that is currently using a Postgres Docker image is compatible with PGlite before switching, which version of Postgres should my Docker image be on?

I see "PostgreSQL 15devel" in a screenshot so I'm assuming that means v15 but explicit documentation on current and future Postgres version usage would be very nice. For example, how will I know when (if) you update to v16?

samwillis1 reply#
Ah, screen shot is out of date. We are on v16.3.
herpdyderp#
Thanks for the quick response! I'd love to see a list of PGlite version vs Postgres version somewhere. Regardless though, congrats on launch! For small projects where I won't care much which Postgres version I'm on, I'll totally give this a shot.
metadat1 reply#
How did they manage to fit Postgres in 3MB?
AlexErrant#
Answered here https://news.ycombinator.com/item?id=41224295

> You might remember an earlier WASM build[1] that was around ~30MB. The Electric team [2] have gone one step further and created a complete build of Postgres that’s under 3MB.
> Their implementation is technically interesting. Postgres is normally multi-process - each client connection is handed to a child process by the postmaster process. In WASM there’s limited/no support for process forking and threads. Fortunately, Postgres has a relatively unknown built-in “single user mode” [3] primarily designed for bootstrapping a new database and disaster recovery. Single-user mode only supports a minimal cancel REPL, so PGlite adds wire-protocol support which enables parametrised queries etc.

Load more comments