Re:What if we treated Postgres like SQLite?
by eirikbakke on Monday September 22, 2025 @12:11PM
(#45335495)
The PostgreSQL data directory format is not very stable or portable. You can't just ZIP it up and move it to a different machine, unless the new machine has the same architecture and "sufficiently" similar PostgreSQL binaries.
In theory the data directory works with any PostgreSQL binaries from the same major version of PostgreSQL, but I have seen cases where this fails e.g. because the binaries were from the same major version but compiled with different build options.
Re:What if we treated Postgres like SQLite?
by tracker1 on Monday September 22, 2025 @01:06PM
(#45336357)
Yeah, I was going to mention, just upgrading between PG versions can be a bit of a pain. Dump/Restore really seems like a less than stellar option of you have a LOT of data. I mean you can stream through gzip/bzip to save space but still.
I often wish that Firebird had a license that people found friendlier to use as it always felt like a perfect technical option for many use cases from embedded to a standalone server. PG has clearly eclipsed it at this point though.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @01:31PM
(#45336762)
On the other hand, and especially if migrating from SQLite, there's typically not _that_ much data. Even hundreds of GBs would probably be okay? Drives are so fast these days. Would be interesting to benchmark.
Re:What if we treated Postgres like SQLite?
by tracker1 on Monday September 22, 2025 @01:48PM
(#45336959)
Maybe that's fair... just feels like a pain when I want to update an app, I have to jump through a few hoops as opposed to just updating the PostgreSQL version in a docker-compose or k8s config.
Would be nice if PG could at least automagically forward update when it starts and a database is from a prior version.
Re:What if we treated Postgres like SQLite?
by eirikbakke on Tuesday September 23, 2025 @10:45AM
(#45347794)
That is the correct way to do it for PostgreSQL.
It does rule out some common SQLite use cases, such as using the database for app persistence. The app would never be able to upgrade the major version of PostgreSQL, unless it bundled PostgreSQL binaries for every major version ever used.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @01:30PM
(#45336741)
Yeah, that really is a great thing about SQLite.
I wonder whether packaging everything in Docker (including a specific Postgres container identified by hash or whatever) and deploying on the same architecture would solve this?
Re:What if we treated Postgres like SQLite?
by OutOfHere on Monday September 22, 2025 @03:02PM
(#45337960)
I would never ever zip up a PostgreSQL data directory and expect it to restore elsewhere. I would use a proper export. If the export is too slow, it could help to use streaming replication to write intermediate files which can be moved to a backup location.
Even with SQLite, for a simple file copy to work reliably, one has to set these three:
Re:What if we treated Postgres like SQLite?
by mutagen on Monday September 22, 2025 @11:27AM
(#45334792)
Some apps do, the most used I know of is Blackmagic's Davinci Resolve, the video editor with a relatively full featured free edition available. I think this has more to do with its roots being in a high end networked environment but still, the local desktop version installs Postgres.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @02:08PM
(#45337264)
Oh, interesting! But that's more of a desktop application now, right? I was thinking of web servers when writing the article, but I can see how that's not totally clear. :-)
For heavy duty production use (i.e., pushing the actual HW limits), I would feel more comfortable with the SQLite vertical. Unix sockets are fast, but you are still going across process boundaries. All of SQLite can be ran on the same thread as the rest of the application. This can dramatically reduce consumption of memory bandwidth, etc.
Re:What if we treated Postgres like SQLite?
by bluGill on Monday September 22, 2025 @12:00PM
(#45335319)
Memory bandwidth I don't worry about much - most of the time you should settup a small database with just enough data for that test, which hopefully is fast. However sockets and processes are a worry as starting as there are places things can go wrong not related to your test and then you have flakely tests nobody trusts.
Re:What if we treated Postgres like SQLite?
by HackerThemAll on Tuesday September 23, 2025 @06:58PM
(#45353901)
> most of the time you should settup a small database with just enough data for that test, which hopefully is fast.
Yeah, this way you're not going to notice performance issues with your data model or application. Test databases should be of sizes comparable to what's expected in production, specifically after several years in production.
Re:What if we treated Postgres like SQLite?
by beckford on Monday September 22, 2025 @01:44PM
(#45336911)
Not OP, but I think it does run Postgres as a process. However, IMHO the general use case for SQL is for external actors (humans, machines) to get access to the underlying data in a structured way. So I see a benefit for a true in-process embedding of Postgres if the process exposed a Postgres TCP/IP port 5432, etc. (Hook your software up to a query tool, a reporting interface, etc.)
Beyond that, why care whether the "embedding" involves a spawned process? It still works great for integration tests which I suspect is the main use case, and for specialized data analysis software where a spawned process is no big deal.
Re:What if we treated Postgres like SQLite?
by nu11ptr on Monday September 22, 2025 @12:13PM
(#45335515)
> Does this use an external binary or CGO or Wazero (Wasm) or is it rewritten in Go?
Since Postgres is always a network connection, I don't believe any CGo is required.
> I try to avoid CGO if I can because it adds compile-time complexity, making it unfriendly for a user to compile.
Using zig as your C compiler mostly fixes this, but you can't 100% get rid of the complexity, but I've cross compiled using Zig cc to Windows/Mac/Linux pretty easily via CGo.
Re:What if we treated Postgres like SQLite?
by xarope on Monday September 22, 2025 @10:18PM
(#45342100)
You got my hopes up, but it's WASM for now, not something I could add into a golang [1] or python app and have running like sqlite. OK, still hoping...!
Re:What if we treated Postgres like SQLite?
by whartung on Monday September 22, 2025 @11:23AM
(#45334732)
I don’t recall the mechanics but I do know that folks have bundled starting a local instance of PG solely for unit tests.
There’s a pre-install step to get PG on the machine, but once there, the testing framework stands it up, and shuts it down. As I recall it was pretty fast.
The most annoying part of it is that Postgres absolutely detests running as PID 0, which makes running `make check` in Docker containers an unnecessarily frustrating experience. I understand why Postgres rejects PID 0 by default, but I would really like for them to recognize strcmp(getenv("I_AM_IN_DOCKER_AND_I_DONT_CARE"), "true") or something.
Re:What if we treated Postgres like SQLite?
by OutOfHere on Monday September 22, 2025 @11:51AM
(#45335166)
If I am not mistaken, DuckDB is suitable for columnar analytics queries, less so for multi-column row extractions. Which PG-like functionality does it offer on top?
Re:What if we treated Postgres like SQLite?
by datadrivenangel on Monday September 22, 2025 @12:53PM
(#45336158)
DuckDB does aim to be Postgres compatible from a SQL syntax perspective, but you are 100% correct that it is not optimized for individual transactions. I'm a huge advocate of DuckDB, but strongly consider your life choices if you want to use it as a transactional database.
Re:What if we treated Postgres like SQLite?
by Imustaskforhelp on Monday September 22, 2025 @04:54PM
(#45339325)
is there something like duckdb but suited for transactional database while still being postgres compatible
It might sound confusing but I wish to genuinely have something of a simpler postgres (in sqlite?) and then later if need be, i could migrate to postgres I suppose.
Re:What if we treated Postgres like SQLite?
by nullzzz on Monday September 22, 2025 @12:53PM
(#45336160)
No it’s not ”pg functionality”. It’s close to SQL standard compliance but not close to what Postgres has to offer. Also, single transaction writing at a time, in-process etc.
Re:What if we treated Postgres like SQLite?
by kissgyorgy on Monday September 22, 2025 @11:56AM
(#45335261)
The huge advantage of SQLite is not that it's on the same machine, but it's that is it in process which makes deployment and everything else just simpler.
Re:What if we treated Postgres like SQLite?
by tptacek on Monday September 22, 2025 @11:59AM
(#45335296)
You'd still be incurring client/server IPC for individual database queries, which would cost you one of the benefits of using SQLite (IDGAF-queries that just hammer tables repeatedly because there's almost no cost to doing so).
Re:What if we treated Postgres like SQLite?
by OutOfHere on Monday September 22, 2025 @11:50AM
(#45335154)
SQLite is used more in resource-constrained environments. If I had much memory to waste, I would've used a local PostgreSQL installation to begin with.
Note that advanced vector-embedding querying techniques for approximate nearest neighbor search inevitably always need an absurd amount of memory, so it typically doesn't make sense to use them in a resource-constrained environment to begin with.
Re:What if we treated Postgres like SQLite?
by apalmer on Monday September 22, 2025 @02:02PM
(#45337183)
I upvoted this, because while it was critical it didn't feel meanspirited and it was factually correct.
After fully reading the article I came to understand it really was not referring to anything sqllite specific, was really 'what if you ran postgres as an application on a server', there really is nothing more to be gained from reading the article beyond this, and this is kind of the most basic deployment model for postgres for like the last 40 years.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @02:26PM
(#45337492)
Sure, you are correct! But I've already learned about pglite and sqlite-vector from the comments here alone. So if one reads the article AND the comments, I hope it's a net-positive for you, too, even if the article alone didn't give you anything.
And if not, I hope you didn't spend too long reading. :-)
Re:What if we treated Postgres like SQLite?
by 8organicbits on Monday September 22, 2025 @12:39PM
(#45335921)
I do this using the Docker approach, especially for low scale web apps that run on a single VM. I like that its full Postgres versus the sometimes odd limits of SQLite. My usual approach uses a Trafik container for SSL, Django+gunicorn web app, and Postgres container; all running as containers one VM. Postgres uses a volume, which I back up regularly. For testing I use `eatmydata` which turns off sync, and speeds up test cycles by a couple percent.
I haven't tried the unix socket approach, I suppose I should try, but it's plenty performant as is. One project I built using this model hit the HN front page. Importantly, the "marketing page" was static content on a CDN, so the web app only saw users who signed up.
Re:What if we treated Postgres like SQLite?
by JodieBenitez on Monday September 22, 2025 @12:57PM
(#45336233)
> You can just install Postgres on your single big and beefy application server (because there’s just the one when you use SQLite, scaled vertically), and run your application right next to it.
Re:What if we treated Postgres like SQLite?
by ok_computer on Monday September 22, 2025 @01:52PM
(#45337029)
I’ve always worked in a datacenter (non cloud) with separate db servers to the app servers. Besides network latency, what is the advantage of collocating the http server and database server on one machine?
It’s always given me a separation of concerns good feeling by seeing a dedicated db and app server and doesn’t seem like much overhead, given they are nearby machines in datacenter.
Also, our main reason was sharing a database license to have a well resourced multi-tenant/app db sever serving peripheral web app servers.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @02:06PM
(#45337243)
The biggest one is latency. Network latency will almost always be orders of magnitude bigger than I/O latency. There's a whole class of problems that goes away when latency becomes very small.
Re:What if we treated Postgres like SQLite?
by markusw on Monday September 22, 2025 @01:28PM
(#45336714)
Hehe. Yes and no.
In the cloud, as you probably know, the usual way now is to spin up Postgres separately (RDS, Supabase, Planetscale, Crunchy Bridge, you name it). We've gotten so used to it that a different way of doing it is often not even considered.
But I think tooling has come a long way, and there have been a lot of learnings from the cloud, so it's time to swing the pendulum back and reconsider assumptions!
Re:What if we treated Postgres like SQLite?
by srameshc on Monday September 22, 2025 @01:48PM
(#45336961)
One of our web apps need a small subset of data from Postgres and we use DuckDB WASM to keep it clost to front end. Yes, I agree with not using it for for OLTP workloads. But instead of installing like author mentions in the post, this is a light replacement that works perfectly if you need a Postgres like DB in your app. Just have to add a new file, INSTALL postgres, LOAD postgres,
ATTACH 'dbname=mydb user=dbname host=25.25.25.25 password=aaaa AS db (TYPE postgres, READ_ONLY);
You can CREATE TABLE my_duck_table_stream AS
SELECT * FROM db.table_stream;
Re:What if we treated Postgres like SQLite?
by kketch on Tuesday September 23, 2025 @07:38AM
(#45345581)
I've been using postgres as a local database for one of my personal projects, a GUI app or to run python tests that depend on it without having to rely on installing it in my environment.
I created a Python package that downloads an embedded Postgres binary, sets up the database, and gives you a database URL: https://github.com/kketch/tinypg
Re:What if we treated Postgres like SQLite?
by kketch on Tuesday September 23, 2025 @07:58AM
(#45345728)
When not using python, been using this script to create ephemeral postgres databases for tests but also persistent one in my dev containers: https://github.com/eradman/ephemeralpg
I've wrapped it with yet another shell script to make it usable just like this:
In theory the data directory works with any PostgreSQL binaries from the same major version of PostgreSQL, but I have seen cases where this fails e.g. because the binaries were from the same major version but compiled with different build options.
I often wish that Firebird had a license that people found friendlier to use as it always felt like a perfect technical option for many use cases from embedded to a standalone server. PG has clearly eclipsed it at this point though.
Would be nice if PG could at least automagically forward update when it starts and a database is from a prior version.
I love the pg_* commands but they ain't exactly the speediest things around.
It does rule out some common SQLite use cases, such as using the database for app persistence. The app would never be able to upgrade the major version of PostgreSQL, unless it bundled PostgreSQL binaries for every major version ever used.
I wonder whether packaging everything in Docker (including a specific Postgres container identified by hash or whatever) and deploying on the same architecture would solve this?
Our docker-compose.yaml has Postgrs, Redis, OPA, Traefik and then our four services. Works a treat.
One thing we haven't solved for is how to have the PG upgrade work when we update major in the image. Nice that 16 should work for a long while.
Even with SQLite, for a simple file copy to work reliably, one has to set these three:
For sqlite, I would recommend "sqlite3 app.db '.backup backup.db'" though, if that's an option. Guaranteed consistent!
https://learn.microsoft.com/en-us/sql/database-engine/config...
For heavy duty production use (i.e., pushing the actual HW limits), I would feel more comfortable with the SQLite vertical. Unix sockets are fast, but you are still going across process boundaries. All of SQLite can be ran on the same thread as the rest of the application. This can dramatically reduce consumption of memory bandwidth, etc.
Yeah, this way you're not going to notice performance issues with your data model or application. Test databases should be of sizes comparable to what's expected in production, specifically after several years in production.
https://github.com/fergusstrange/embedded-postgres
UPDATE: Actually, I see it is downloaded (and I think cached?). I can't recall if you can embed as an option or not.
Beyond that, why care whether the "embedding" involves a spawned process? It still works great for integration tests which I suspect is the main use case, and for specialized data analysis software where a spawned process is no big deal.
This sounds like it could be pretty useful.
With SQLite, although all approaches are available, my fav is to use https://github.com/ncruces/go-sqlite3 which uses Wazero.
I try to avoid CGO if I can because it adds compile-time complexity, making it unfriendly for a user to compile.
Since Postgres is always a network connection, I don't believe any CGo is required.
> I try to avoid CGO if I can because it adds compile-time complexity, making it unfriendly for a user to compile.
Using zig as your C compiler mostly fixes this, but you can't 100% get rid of the complexity, but I've cross compiled using Zig cc to Windows/Mac/Linux pretty easily via CGo.
https://github.com/electric-sql/pglite-bindings
It would still be missing the standardized disk format aspect of sqlite, but otherwise will be neat.
It's an embeddable Postgres you can run in process as a local client DB, just like SQLite but it's actually Postgres.
[1]https://github.com/electric-sql/pglite/issues/89
There’s a pre-install step to get PG on the machine, but once there, the testing framework stands it up, and shuts it down. As I recall it was pretty fast.
The most annoying part of it is that Postgres absolutely detests running as PID 0, which makes running `make check` in Docker containers an unnecessarily frustrating experience. I understand why Postgres rejects PID 0 by default, but I would really like for them to recognize strcmp(getenv("I_AM_IN_DOCKER_AND_I_DONT_CARE"), "true") or something.
It might sound confusing but I wish to genuinely have something of a simpler postgres (in sqlite?) and then later if need be, i could migrate to postgres I suppose.
https://electric-sql.com/
Note that advanced vector-embedding querying techniques for approximate nearest neighbor search inevitably always need an absurd amount of memory, so it typically doesn't make sense to use them in a resource-constrained environment to begin with.
Next embedded model version moved to 8MB flash and 64MB RAM with the same software infrastructure.
After fully reading the article I came to understand it really was not referring to anything sqllite specific, was really 'what if you ran postgres as an application on a server', there really is nothing more to be gained from reading the article beyond this, and this is kind of the most basic deployment model for postgres for like the last 40 years.
And if not, I hope you didn't spend too long reading. :-)
I haven't tried the unix socket approach, I suppose I should try, but it's plenty performant as is. One project I built using this model hit the HN front page. Importantly, the "marketing page" was static content on a CDN, so the web app only saw users who signed up.
So you do periodic backups, not incremental on every write or something (read replica-like)?
It's important to me to not lose any data once committed if at all possible.
(For testing, I've sped everything up by running migrations on `template1` and every test gets a random database name. Works wonders.)
Am I getting old ? Seems obvious to me.
It’s always given me a separation of concerns good feeling by seeing a dedicated db and app server and doesn’t seem like much overhead, given they are nearby machines in datacenter.
Also, our main reason was sharing a database license to have a well resourced multi-tenant/app db sever serving peripheral web app servers.
In the cloud, as you probably know, the usual way now is to spin up Postgres separately (RDS, Supabase, Planetscale, Crunchy Bridge, you name it). We've gotten so used to it that a different way of doing it is often not even considered.
But I think tooling has come a long way, and there have been a lot of learnings from the cloud, so it's time to swing the pendulum back and reconsider assumptions!
I meet an unexpected number of young devs that:
- Find hypermedia to be exotic. JSON web API is the only way that makes sense to them.
- Say they use the cloud to "save money".
- Use third-party services for things as basic as authentication because "it's hard".
- Encode security stuff in the frontend code.
It's the cycle of life.
I'm curious, when do you want to treat your Postgres like SQLite? :-) That's basically the opposite of what I was thinking of in the article.
ATTACH 'dbname=mydb user=dbname host=25.25.25.25 password=aaaa AS db (TYPE postgres, READ_ONLY);
You can CREATE TABLE my_duck_table_stream AS SELECT * FROM db.table_stream;
It's just fun
I created a Python package that downloads an embedded Postgres binary, sets up the database, and gives you a database URL: https://github.com/kketch/tinypg
It downloads pg binaries from this project: https://github.com/zonkyio/embedded-postgres-binaries. There are other similar projects listed on that page that provide this for Java, Go, Rust and Node
I've wrapped it with yet another shell script to make it usable just like this:
`export DB_URL=$(./pgtest.sh)`
This version (pgtest.sh), just creates a disposable ephemeral postgres: https://gist.github.com/kketch/d4e19a7fb6ebc1cfc265af44c1b41...
This version (pgdev.sh), starts a postgres instance (if not already running) and persists the DB. Also supports seeding it with a SQL script (dev_seed.sql): https://gist.github.com/kketch/88bb5b766994e247a9f2c37f13306...