Minipg: PostgreSQL as a Single Executable

272 points43 comments18 hours ago
t3ntxcles

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?

show comments
Ciantic

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.

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...

show comments
progrium

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.

show comments
nomercy400

Impressive. Uses postgres alpine's docker image, without docker. Instead it used h9, a young embedded hypervisor tool.

iamcalledrob

Does this do anything interesting that postgres in a Nix dev shell doesn't?

jgarzik

In Other Words, RooDB: https://github.com/jgarzik/roodb

anilgulecha

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.

show comments
WanderZil

Nice that a command starts a shared background server if needed, then shuts it down after a minute idle.

kennethh

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

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.

Onavo

How does it compare to https://pglite.dev

show comments
msrbuilds

This can be a good testing tool

dolmen

Looks useful for CI.

canadiantim

Can this be used on in a mobile app? Is there any postgres that can be used in a mobile app with extensions? Like pg_search?

cantaffordsht

nice, but could it please not download 35 on page enter? I was curious and luckily on train wifi

show comments
pelasaco

this https://progrium.github.io/hyper9/ sounds really impressive..

show comments
galaxyLogic

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.

show comments