August 12th, 2024

Show HN: PGlite – in-browser WASM Postgres with pgvector and live sync

PGlite is a lightweight, embeddable Postgres database under 3MB, operating in a WebAssembly environment, supporting dynamic extensions, reactive programming, and AI-driven database creation via Supabase.

Read original articleLink Icon
ExcitementInterestAppreciation
Show HN: PGlite – in-browser WASM Postgres with pgvector and live sync

PGlite is a lightweight, embeddable version of Postgres that operates locally in a WebAssembly (WASM) environment, with a total size of under 3MB when gzipped. It features a dynamic extension loading mechanism, allowing for the integration of various extensions such as pgvector and PostGIS. PGlite supports reactive programming, enabling data loading, synchronization, and live query capabilities. Users can create and publish a Postgres database using AI through Supabase, and the platform offers an interactive experience directly in the browser. PGlite is dual-licensed under Apache 2.0 and the PostgreSQL License.

- PGlite is a lightweight Postgres database running in a WASM environment.

- It supports dynamic extension loading, including pgvector and PostGIS.

- The platform offers reactive programming features for data synchronization and live queries.

- Users can create and publish databases using AI through Supabase.

- PGlite is dual-licensed under Apache 2.0 and the PostgreSQL License.

AI: What people are saying
The comments on PGlite highlight several key themes and points of interest among users.
  • Many users appreciate PGlite's lightweight nature and ease of installation, comparing it favorably to Docker and SQLite.
  • There is a strong interest in its compatibility with various frameworks, particularly Next.js, and its potential for integration testing.
  • Users are curious about performance comparisons with traditional PostgreSQL and SQLite, as well as the implications for data persistence and syncing.
  • Several comments express excitement about the potential for PGlite to support additional programming languages beyond JavaScript.
  • Questions arise regarding specific features, such as support for live queries, at-rest encryption, and the relationship with ElectricSQL.
Link Icon 37 comments
By @simonw - 2 months
I'd seen this running in a browser before (the ~3MB download is really impressive for that), but I hadn't clocked that it runs server-side with Node.js and Bun as well: https://pglite.dev/docs/

Since that's still not spinning up an actual network server, that feels like it's an alternative to SQLite - you can spin up a full in-process PostgreSQL implementation, that persists to disk, as part of an existing Node.js/Bun application.

That's really interesting!

I'd love to use this from Python, via something like https://github.com/wasmerio/wasmer-python or https://github.com/bytecodealliance/wasmtime-py - has anyone run PGlite via one of those wrappers yet?

By @creativedg - 2 months
Huge fan of PGlite.

It's the perfect solution to have Postgres without the need of Docker. With just `npm install`, you can have a Postgres instance on your computer. So, it's extremely easy to onboard a new developer in your team.

And, the good news, PGlite works perfectly with Next.js.

I'm using PGlite in local and development environment with Next.js Boilerplate: https://github.com/ixartz/Next-js-Boilerplate

With only one command `npm install`, you can have a full-stack application, which also includes the database (a working Postgres). And, no need to have/install external tools.

By @sgbeal - 2 months
To keep the next person from having to look (or ask without looking): it supports browser-side persistence via IndexedDB and OPFS: <https://pglite.dev/docs/filesystems>
By @Cu3PO42 - 2 months
When I saw the headline, I immediately thought "I bet this would go really well with ElectricSQL", so it's great to see this coming from you!

The immediate DX is incredible and I'm itching to use PGLite (and ElectricSQL) in a production project, I expect it would remove quite a few pain points I'm currently experiencing. (Also, I just like working with CRDTs.)

I don't have any constructive criticism to offer right this moment, but I just wanted to congratulate you on the launch and an incredible looking product!

By @satvikpendem - 2 months
Congrats on the Show HN. I follow the ElectricSQL Discord server and I was distinctly interested in this but for other languages than TypeScript, so it's nice to see that making it language independent is high on your list. I also saw that ElectricSQL is being rewritten due to architectural changes, does that impact PGlite at all or are they separate projects now? What is the relationship between PGlite and ElectricSQL as well, just curious?

Also, fun etymological thing, SQLite is actually SQL-ite, as in, urbanite, not SQ-Lite, but due to rebracketing [0] and libfixing [1], now people seem to use the -lite suffix rather than the -ite one, presumably because lite actually implies something whereas ite would not, as much. It's like how helicopter is actually helic and opter, a helical wing that spins, but now people think of it as heli and copter, calling other things related to it like helipad, or quadcopter, as Wikipedia states.

[0] https://en.wikipedia.org/wiki/Rebracketing

[1] https://en.wikipedia.org/wiki/Libfix

By @Retr0id - 2 months
Normally I'd say the main difference between postgres and SQLite is that the latter is in-process. Now that they can both be in-process, is there a more detailed comparison of the two? When might I prefer one over the other?
By @bezbac - 2 months
I recently experimented with using pglite for API integration tests in one of my side projects. It worked pretty well and has much better DX than using something like testcontainers[0] to spin up postgres running in docker.

[0]: https://testcontainers.com

By @bearjaws - 2 months
PGlite / ElectricSQL is definitely something I want to use in a future job.

The ability to replicate and subscribe to the changes, all within the browser seems incredibly powerful.

Having worked on medical software that runs a 2,000,000+ patient workload that perform refills for chemotherapy/HIV/immuno drugs, where it was common for people to trample each others work as they ran insurance, called patients etc...

We had to roll our own locking system that relied on interval functions (yay IE7) and websockets... This meant when you called the patient, someone running financial assistance would be unable to work on the same profile.

I can envision other uses for FTS or even vector search locally, since they are insanely expensive at scale.

By @saurik - 2 months
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.
By @ZitchDog - 2 months
> 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?

By @herpdyderp - 2 months
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?

By @metadat - 2 months
How did they manage to fit Postgres in 3MB?
By @cpursley - 2 months
Woah, this is neat - insane that it can handle extensions.

Just added a new section to my "Postgres Is Enough" gist:

https://gist.github.com/cpursley/c8fb81fe8a7e5df038158bdfe0f...

By @FlyingSnake - 2 months
PGLite is a wonderful achievement and I've a fan of it since it's early days.

If they get it to a stage where other languages apart from JS can use it, it could be revolutionary. The possibilities are limitless.

By @AlexErrant - 2 months
Bug report? On https://pglite.dev/repl/ running `SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat & rat'::tsquery;` works, which is cool.

However, running `SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat');` fails with `y is not a function`. Then trying to run the first query yields `null`, which is weird. I can open an issue if you want :)

By @NetOpWibby - 2 months
This is exciting. My database of choice is EdgeDB, which uses Postgres under the hood. It's not so far-fetched to imagine EdgeDB in the browser now!
By @cheema33 - 2 months
The filesystems page at https://pglite.dev/docs/filesystems says the following:

> "We would recommend using the IndexedDB VFS in the browser at the current time as the OPFS VFS is not supported by Safari."

Is it possible to configure PGLite to use IndexedDB on Safari and OPFS on Chrome & Firefox?

By @drzaiusx11 - 2 months
Anyone know if something similar is available for MySQL/Maria? This is very cool, especially given the tiny size of it
By @srameshc - 2 months
If I understand correctly, this is like SQLite, but Postgres. I love SQLite, but sometimes I need a little more. So, no more saving Date as text and we have arrays, jsonb etc and all the good stuff from Postgres. Am I right ?
By @ChrisArchitect - 2 months
Related:

Subabase announcement post

Postgres.new: In-browser Postgres with an AI interface

https://news.ycombinator.com/item?id=41224286

By @blueprint - 2 months
Anyone know how this would play with at-rest encryption extensions?
By @ggregoire - 2 months
I was gonna ask what do people use to sync their local pg with their remote pg, but turns out, that's exactly what the authors are building. Cool stuff, and gratz on pglite!
By @wejick - 2 months
Curious to know How "vanilla" the pglite compared to the vanilla postgres? I saw many people are using this for automated testing and dev environment.
By @batmansmk - 2 months
Pretty awesome. Would love to use it in CI and locally for our PG product. We use Prisma, so I guess we have to wait for the connector that looks like pg to plug it in.
By @isoprophlex - 2 months
That's great! Corpo beancounters want us to move off docker on EC2 onto bare metal, making both dev and deploy experience terrible. This will help ease pain!
By @loevborg - 2 months
PGLite is amazing for integration testing of queries against a real in-memory db.

Is it possible to use PGLite for that purpose in non-JS environments, like e.g. golang?

By @Kinrany - 2 months
Can it run in Node while still persisting data to disk?
By @vivzkestrel - 2 months
How does it compare with https://postgres.new/
By @sam_perez - 2 months
Oh cool, how would you compare this to DuckDB?
By @makkesk8 - 2 months
Awesome work! A killer feature of sqlite that I would love to see in pglite would be javascript window functions.
By @sabr - 2 months
This is amazing! Will there be something like Litestream/rqlite for PGlite?
By @revskill - 2 months
The migration docs to integrate with Vite/webpack is still lacking though.
By @namanyayg - 2 months
How does the performance compare to actual postgres?
By @teaearlgraycold - 2 months
Heads up, the supabase link on the front page 404s
By @non- - 2 months
Would really like to see a benchmarking analysis vs SQLite. How do they compare on memory usage and overhead?

I already default to SQLite for new side projects with the idea that "eventually I'll migrate to Postgres if this project gets legs", so switching to PGlite feels like a no-brainer as long as it's not going to weigh my apps down or force me to upgrade out of whatever entry-level server solution I'm using is for a given project.

EDIT: Found the benchmarks here https://pglite.dev/benchmarks

By @AIDataWhiz - 2 months
This is exactly the tool I needed and I will try it out in my new project. Thanks for your contribution