Cool hack, getting fork-per-connection postgres running with no kernel is quite interesting
I'm struggling to see the use case for minipg itself. For embedded or in-process postgres there's pglite as mentioned in comments. For dev/test parity there's embedded-postgres (go, java, node, python), which downloads native binaries and gives you a throwaway postgres with no docker. These by themselves cover what most people would want from "sqlite-style postgres," without the hypervisor layer or significant slow down.
Is minipg intended to become a real tool, or is it mainly a showcase for h9, with Postgres as the hard case that proves it works?
gavinray 6 hours ago [-]
I was confused about the use case as well but the authors blog post linked in this thread clears it up. I'm not sure I agree with it, personally would just run WASM postgres:
> So when you find self-hostable open source software you'd like to run on your own computer, it can be daunting when it says it requires Postgres. Now you're responsible for setting up a database and getting it ready for the software to use.
> Sure, you can run Postgres in Docker, and plenty of projects recommend it. But now you have two dependencies. If you don't already have Docker, you have to install it, which can mean a VM and a daemon on your machine. Then you have to run Postgres in it and make sure it's running whenever you use the software. That's a lot just to try something you don't know you want yet.
> Wouldn't it be great to have the SQLite experience, but with Postgres?
> That's miniPG . It isn't Postgres as a library. There's already a WASM project for that, reasonably called PGlite. miniPG is closer to the SQLite CLI
progrium 3 hours ago [-]
The answer is in there, but I think you're referencing the wrong part of the post. The real kicker was PGlite not being able to be a drop-in replacement for an application expecting multiple connections/sessions, where it might need to query while in a separate transaction.
singpolyma3 5 hours ago [-]
I just don't understand what's daunting about apt install postgresql
rpdillon 2 hours ago [-]
I hate people that recite credentials, but suffice to say I'm very familiar with postgres at-scale in production. I can give details if that's not compelling.
I still don't use postgres for my small projects, because sqlite gets you so far, so fast. You can just apt install postgres, but then you have all the aux questions:
When do you upgrade?
How is authentication handled?
How are we doing backups?
How do I deploy in production?
How do I restore from a backup?
With sqlite, these are either not as relevant or they have trivial answers. With postgres, each is another project/process to track.
But of course, the way you frame your question sides-steps these challenges, and instead focuses on how to install the software, which was never the challenge being tackled.
singpolyma3 19 minutes ago [-]
The question was for self hosting though. So not at scale.
So upgrade when you're working in your stack and upgrading things.
Auth using Unix socket as per defaults
Backup by backing up your whole server
Is any of this quite sufficient for at scale? Often not, I agree. But that wasn't the context of the question.
Ciantic 10 hours ago [-]
I can see this very useful for small self-hosted applications. I could imagine deploying this instead of sqlite in some cases. Though having a real server is not maybe ideal for self-hosted apps.
For unit tests I've found that I don't need PGLite or other tools, only podman and official images.
Regular postgres starts in 800 milliseconds, TimeScale DB in 1 second.
I have setup where first unit test that starts podman container and after finish it ends it all. On each test I create new database (or search path), time it takes to create db is in milliseconds.
They actually run as a library, like sqlite does, with no separate process
ptman 10 hours ago [-]
I've played with databases and schemas for isolating tests, but I think pgtestdb has the winning concept: load fixtures into a template database and clone if for each test https://github.com/peterldowns/pgtestdb
progrium 3 hours ago [-]
Keep in mind there are two ways to think about SQLite. Most commonly, as these comments show, it's thought of as a library. An embedded SQL engine. The second is as a simple CLI-friendly SQL database. Minipg is more about the latter use.
That said, PGlite is great and would have been ideal for the motivating problem, but as my blog post mentions (eventually), it only runs in single connection mode. For better or worse, applications will sometimes perform another query while in another transaction, causing deadlock with PGlite. It's fine if you can avoid that in your app, but makes it not work as a general drop-in replacement for existing apps.
The way I'd rather it be looked at, though, is just as a more convenient, "friendly" way to work with Postgres on the CLI. So maybe it's not for Postgres experts.
ronfriedhaber 2 hours ago [-]
> The second is as a simple CLI-friendly SQL database.
If one needs an ACID database, he would also like programs to perform CRUD operations upon it, which requires a stable ABI. I can't see why one would want a CLI relational database. On the other hand, embedded OLAP databases such as DuckDB are mostly CLI-first and lib-second.
For folks working in this area, may I request a MySQL/mariadb-lite?
pglite is great for browser / testing emulation for PG. MySQL in browser does not have an equally good story. Closest is https://github.com/ephpm/litewire , but it isnt really MySQL fully.
Can't recommend it but I experimented myself with lite4mariadb and hit a few rough edges, e.g. transactions aren't isolated when the callback is async, memory use is insane. Issues are also disabled on the repo (it's a github fork), so there's nowhere to report bugs.
General issue of both is them being single-connection and being less battle tested.
If translation is acceptable, wordpress playground's sqlite driver (sqlite-database-integration) parses mysql into an ast which is based on my experience is the most proven approach in browser today.
Would be genuinely excited if mysql in WASM gets more attention.
anilgulecha 3 hours ago [-]
Very cool - thanks for these pointers.
WanderZil 8 hours ago [-]
Nice that a command starts a shared background server if needed, then shuts it down after a minute idle.
kennethh 12 hours ago [-]
This seems to be ideal for testing purposes. Great to use this in a 16gb mac so I do not have to install docker.
maCDzP 9 hours ago [-]
This is cool. I can start building against Postgres and run the db as a file.
Then, when my LLM-assisted project spirals out of control I can move it to a dedicated server.
Anyone got some input on how this compares to lxc?
pelasaco 6 hours ago [-]
i am exactly looking into that right now
arbor-group 6 hours ago [-]
[dead]
patryk_builds 8 hours ago [-]
[dead]
robertpaschal 6 hours ago [-]
[dead]
kannsky 6 hours ago [-]
[dead]
amintt 6 hours ago [-]
[dead]
tthanhdev 12 hours ago [-]
[dead]
minchaozhu 7 hours ago [-]
[dead]
1homsi 6 hours ago [-]
[dead]
zaiyuan_dev 14 hours ago [-]
[dead]
galaxyLogic 15 hours ago [-]
This I think is wonderful. I've used SQLite on Node.js but had many problems trying to deploy it together with my app, because there were so many (moving) parts to the system and they had to get deployed into the Vercel PKG EXE. It worked well until it didn't. But if there is only one file needed to include the database "server", it will be so much more robust and resilient to environment changes around the build-process.
So, does this work well on Node.js? If it does I'm willing to make the jump from SQLite to this.
notpushkin 13 hours ago [-]
Since minipg is a standalone executable, so I’m not sure it would work there? If if Vercel has WASM support, check out https://pglite.dev/ -- I’m using it with Node apps for local dev and it works nearly flawlessly. (In production, I tend to run a full Postgres setup on my own server, or just use hosted Postgres.)
Edit: yeah, I also got confused about the “Vercel PKG EXE”, haha
rnbrgr 15 hours ago [-]
May I ask what moving parts you're referring to that make deploying it cumbersome?
Since SQLite comes natively with Node.js (node:sqlite since Node.js v22.5.0) things got a lot easier. Before that the npm packages relying on native builds were a bit annoying for me as well.
galaxyLogic 15 hours ago [-]
I haven't worked with it lately since the database is not a critical part of my system. The problems were basically caused because SQLite requires non-JS libraries and they need to be found in the right place, and compiled and packaged into Vercel-PKG exe, and I got obscure error-messsages.
Happy to hear things are getting smoother with Node.js SQLite, but then I have the other problem that Vercel-PKG support stopped at a specific Node.js level, so I wouldn't be able to use the native Node.js SQLite anyway I assume .
Now lately I discovered that there is an open-source fork of Vercel-PKG which supports later Node.js versions:
npmjs.com/package/@yao-pkg/pkg?activeTab=readme&__cf_chl_tk=eDzgWvIL2OkIxMCGlCoLW6Mi2t2ciRkE6HMYKl46MnY-1795671127-1.0.1.1-fY.UrK80ucEtTwp1j_XEPi4eI5iwficmiVkl4qjE1HY .
Once I get my build-process ported to that or something similar I will certainly revisit the database question again for my project.
But then whether the Node.js native SQLite runs after compiling it into the Vercel-PKG exe lookalike I don't know (yet).
I'm struggling to see the use case for minipg itself. For embedded or in-process postgres there's pglite as mentioned in comments. For dev/test parity there's embedded-postgres (go, java, node, python), which downloads native binaries and gives you a throwaway postgres with no docker. These by themselves cover what most people would want from "sqlite-style postgres," without the hypervisor layer or significant slow down.
Is minipg intended to become a real tool, or is it mainly a showcase for h9, with Postgres as the hard case that proves it works?
I still don't use postgres for my small projects, because sqlite gets you so far, so fast. You can just apt install postgres, but then you have all the aux questions:
With sqlite, these are either not as relevant or they have trivial answers. With postgres, each is another project/process to track.But of course, the way you frame your question sides-steps these challenges, and instead focuses on how to install the software, which was never the challenge being tackled.
So upgrade when you're working in your stack and upgrading things. Auth using Unix socket as per defaults Backup by backing up your whole server
Is any of this quite sufficient for at scale? Often not, I agree. But that wasn't the context of the question.
For unit tests I've found that I don't need PGLite or other tools, only podman and official images.
Regular postgres starts in 800 milliseconds, TimeScale DB in 1 second.
I have setup where first unit test that starts podman container and after finish it ends it all. On each test I create new database (or search path), time it takes to create db is in milliseconds.
Trick is to use `--image-volume tmpfs` when starting the container. I have my pg test server as Rust in here: https://github.com/Ciantic/app-frame/blob/main/crates/pgtest...
I think you would be better off with either https://github.com/electric-sql/pglite or https://github.com/f0rr0/oliphaunt
They actually run as a library, like sqlite does, with no separate process
That said, PGlite is great and would have been ideal for the motivating problem, but as my blog post mentions (eventually), it only runs in single connection mode. For better or worse, applications will sometimes perform another query while in another transaction, causing deadlock with PGlite. It's fine if you can avoid that in your app, but makes it not work as a general drop-in replacement for existing apps.
The way I'd rather it be looked at, though, is just as a more convenient, "friendly" way to work with Postgres on the CLI. So maybe it's not for Postgres experts.
If one needs an ACID database, he would also like programs to perform CRUD operations upon it, which requires a stable ABI. I can't see why one would want a CLI relational database. On the other hand, embedded OLAP databases such as DuckDB are mostly CLI-first and lib-second.
pglite is great for browser / testing emulation for PG. MySQL in browser does not have an equally good story. Closest is https://github.com/ephpm/litewire , but it isnt really MySQL fully.
Can't recommend it but I experimented myself with lite4mariadb and hit a few rough edges, e.g. transactions aren't isolated when the callback is async, memory use is insane. Issues are also disabled on the repo (it's a github fork), so there's nowhere to report bugs.
General issue of both is them being single-connection and being less battle tested.
If translation is acceptable, wordpress playground's sqlite driver (sqlite-database-integration) parses mysql into an ast which is based on my experience is the most proven approach in browser today.
Would be genuinely excited if mysql in WASM gets more attention.
Not very nice, yeah, I’d put that behind a “play” button of sorts.
So, does this work well on Node.js? If it does I'm willing to make the jump from SQLite to this.
Edit: yeah, I also got confused about the “Vercel PKG EXE”, haha
Happy to hear things are getting smoother with Node.js SQLite, but then I have the other problem that Vercel-PKG support stopped at a specific Node.js level, so I wouldn't be able to use the native Node.js SQLite anyway I assume .
Now lately I discovered that there is an open-source fork of Vercel-PKG which supports later Node.js versions: npmjs.com/package/@yao-pkg/pkg?activeTab=readme&__cf_chl_tk=eDzgWvIL2OkIxMCGlCoLW6Mi2t2ciRkE6HMYKl46MnY-1795671127-1.0.1.1-fY.UrK80ucEtTwp1j_XEPi4eI5iwficmiVkl4qjE1HY .
Once I get my build-process ported to that or something similar I will certainly revisit the database question again for my project.
But then whether the Node.js native SQLite runs after compiling it into the Vercel-PKG exe lookalike I don't know (yet).