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.
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.
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.
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.
Hi there, would you like to share the progress of converting PGlite into a native system library? I can see there is a repo for that, but it hasn't been updated for 5 months
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.
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.
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?
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.
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.
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?
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.
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.
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.
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
PGlite is embedded so you can't really connect to PGlite using the PG clients. Dbfor.dev runs the PG protocol in the server and use Websockets & PGlite so any PG client can connect to your browser using PG protocol.
The hard work is done by PGlite and we use PGlite, it just enables PGlite to be accessible from everywhere.
41 comments
[ 2.5 ms ] story [ 65.2 ms ] threadIs there a way to compile this as a native library? I imagine some of the work should be reusable.
Here's the project if anyone is interested: https://github.com/adhamsalama/sqlite-wasm-webrtc
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.
Nonetheless, this could be interesting for data heavy SPA's.
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?
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.
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.
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?
Definitely going to try this out for tests and see how it goes.
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.
[1] https://docs.doltgres.com/introduction/installation
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?
At this point, this should be built into the browser which could fetch signed db data and be extremely performant.
The result is a PG server that fully lives in your browser: https://dbfor.dev
The hard work is done by PGlite and we use PGlite, it just enables PGlite to be accessible from everywhere.