I'd love to to use PGLite in a non-JavaScript runtime. For example, embed PGLite into my Go CLI with a WASM runtime and use PGLite as a replacement for SQLite.
https://github.com/electric-sql/pglite/issues/89 makes it sound like there's "third-party" bindings for Rust. Is there any interest in "official" PGLite bindings to other languages?
PGlite is fantastic. I use it for my in-browser PostgreSQL server for development. It implements the PG protocol on the server; when clients connect, we forward queries to the user's browser, which runs PGlite under the hood.
The result is a PG server that fully lives in your browser: https://dbfor.dev
Hello, can you please summarize the advantages of PGLite compared to SQLite?
I've never used Postgres before, my work is mostly on the embedded domain using files and a lot of browser execution on the client side.
With SQLite there is simplicity attached to the databases, with PGLite I see a lot of interesting extensions to try out but what would the big difference when compared to SQLite?
This is very cool. Having to always set up a server is one major downside of Postgres, with cumbersome updates being the second. This solves the first and has potential to help with the second.
Is there a way to compile this as a native library? I imagine some of the work should be reusable.
At work we started building a new internal service and decided to try this out for the test setup. We built a small wrapper which seamlessly uses PGLite when running tests and actual Postgres instance otherwise. Great success!
The ability to .clone() the database to create "checkpoints" is also great for tests, as we can run all of the migrations and return to that clean state between each test. Running 50 test suites in parallel is also so easy with this setup.
For unit testing, I still use TestContainers which spins a full Postgres in Docker. But new alternatives like this make py-pglite (https://github.com/wey-gu/py-pglite) possible which is Python unit testing with PGlite. Even so, for Python unit testing I'm more confident in something like pgserver (https://github.com/orm011/pgserver) which offers the full, real Postgres in a lightweight pip package. Note: my take is specifically for unit testing, not other use cases!
I'm so optimistic about this, especially in the context of local-first web applications. With Postgres on both the client and the server, and something like PowerSync or ElectricSQL to keep the two together, you get a homomorphic database environment between client and the server. That has a lot of architectural benefits I'm actively exploring. The client and the server can share a lot more code, for one.
But I read the following posts, and I have some serious concerns about PGlite's performance:
https://antoine.fi/sqlite-sync-engine-with-reactivity – describes memory leaks, minute-long db startup time, and huge slowdowns with live queries
https://github.com/marcus-pousette/sqlite3-bench - shows performance dropping to multi-second territory for inserts and lookups, compared to sqlite which is significantly faster
It sadly makes me slightly skeptical about adopting what effectively feels like a hack... SQLite has obviously had decades of adoption and I'm not expecting PGlite to match that level of legacy or optimisation - but it's enough to give me pause.
I really, really want to adopt PGlite in a project I'm currently architecting, so would love some insight on this if anybody has any!
Using this for testing... it feels like a sweet spot between in-memory SQLite and spinning up a full Postgres instance. I'd been looking for this for a while and I'm pretty happy with the faster tests. And so far no blockers from its limitations.
There is also Doltgres [1] which is a single-file Postgres. Just like Deno you download and run a single .exe file and voila! you have Postgres!
previous Show HN post submitted by the author (109 comments) - https://news.ycombinator.com/item?id=41224689
Very neat.
Impressive performance: https://pglite.dev/benchmarks
Even has Drizzle ORM integration: https://orm.drizzle.team/docs/connect-pglite
I will explore this for use in my unit / integration tests. It looks pretty amazing.
I am confused why all my recent compiled tooling (tsgo, biomejs) are shipping native binaries (thus creating multiple binaries, one per supported platform) and not WASM tools that can run cross platform? Is it because of startup times, poor tooling, etc?
One thing this (and any browser-embeddable data store) are fantastic for is vibe coding interactive prototypes for user research.
AI-generated code that doesn’t need to be production ready has been a real boon to usability and design work. Testing with users something that actually saves and displays data, and seeding the app with realistic-looking datasets in both shape and size, reveals usability issues that you just don’t discover in Figma prototypes.
If a product team isn’t performing user research with interactive prototypes as a core part of their dev and design lifecycle, they’re doing themselves a real disservice. It’s so easy now.
Really cool project! We had a situation a while back where some of our e2e tests needed the DB to be in very specific states. Technically we could have handled it with fixtures/transactions/schema resets, but doing that cleanly across a bunch of tests was pretty painful in our setup at the time
For a few edge-case scenarios we ended up mocking the DB layer (which obviously stops being a true e2e test). Something like PgLite would've been a perfect middle ground - real Postgres, zero container overhead, easy to spin up isolated instances per test, and a clean slate for every run.
Oh, I thought i hallucinated this last night
I was evaluating local storage solutions a while back and I tried setting up PGlite, but unfortunately I couldn't get it to work in Next.js with Turbopack in a web worker.
I've been using SQLite locally instead with wa-sqlite and it's been working great for my use case so far. It's also more lightweight.
This looks impressive. Could someone familiar with Postgres internals explain the hidden trade-offs of this approach?
I understand the obvious limitations of it being embedded/single-host, but I'm curious about the engine itself. Does running in this environment compromise standard features like ACID compliance, parallel query execution, or the ecosystem of tools/extensions we usually rely on?
The last time I ended up trying something like this I was implementing postgres features that the mocks didn’t.
Now, I just tested against a real database in a docker container. I have over 1k tests that run about 1.5 mins. I’m pretty happy with that.
I guess given that, testing isn’t quite the use case for this (for me). Wonder what else this could be used for.
I'm using this with a Bun project for my testing needs. I spin PGLite at the beginning, throw it all away at the end. It's not as nice as transactionally isolated testing (a la Ruby on Rails, or Elixir), but it's a fine replacement until I have time to replicate it.
This is interesting, I've been looking for something like this that I can use in unit/integration tests. I've used the mongodb memory server for testing but never found something like that for Postgres that didn't require running a full PG server instance...
Definitely going to try this out for tests and see how it goes.
Are people using this in SPA applications with success? I saw on the website that syncing via ElectricSQL is in alpha and that no CRDT is available, afaik. Any other options? Also, I guess pgsql extensions are out of scope?
Nonetheless, this could be interesting for data heavy SPA's.
It's cool that this is possible, is this just for fun or are there good use-cases for this?
What is the advantage of using something like this instead of the IndexedDB Browser Feature
Can this be used as a read-replica to a normal PG instance? I'm thinking synced browser cache here.
Is there similar attempt for MySQL?
I tried to use this when I was building a project about peer-to-peer database sharing in the browser using WebAssembly and WebRTC, but I found it a bit heavy so I used SQLite instead.
Here's the project if anyone is interested: https://github.com/adhamsalama/sqlite-wasm-webrtc
Is it just me or is downloading 3MB for the DB runtime plus the database itself, kind of crazy?
At this point, this should be built into the browser which could fetch signed db data and be extremely performant.
Is there a PGlite but like SQlite (so without a running a server), just with the PG flavor of SQL instead of Sqlite's?
ccc
Hey everyone, I work on PGlite. Excited to see this on HN again.
If you have any questions I'll be sure to answer them.
We recently crossed a massive usage milestone with over 3M weekly downloads (we're nearly at 4M!) - see https://www.npmjs.com/package/@electric-sql/pglite
While we originally built this for embedding into web apps, we have seen enormous growth in devtools and developer environments - both Google Firebase and Prisma have embedded PGlite into their CLIs to emulate their server products.