News for hackers. Stuff that matters.
Re:In Praise of PostgreSQL by pedrocr on Thursday August 05, 2021 @01:11PM (#28076572)
I'm always amazed at the amazing reviews SQLite gets, particularly in a thread about PostgreSQL. I get the angle of SQLite competing with fopen(). If what you need is a file format you can do a lot worse than SQLite. But I've worked on multiple desktop apps where the only reason SQLite gets used for the internal database is that PostgreSQL doesn't have a mode where you can ship it as part of the app easily and asking the user to setup a database is a non-starter. If not for that the performance benefits of the swap would be very significant. I suspect if PostgreSQL shipped such a mode a very large percentage of SQLite uses would switch over.
Re:In Praise of PostgreSQL by sa46 on Thursday August 05, 2021 @10:27PM (#28082628)
It's possible but tediuos to run Postgres standalone. I packaged Postgres up for our Bazel build which requires a hermetic environment. The hard parts were:

1. Postgres doesn't really didn't want to be statically compiled, according to [1].

2. Messing with LD_LIBRARY_PATH to point to an embedded glibc and openssl when running the heremetic postgres binaries.

3. Postgres will absolutely refuse to run the server process as root. That's sensible for a production environment but a pain in CI because it would require setting up another user on machines. I patched away the problem to allow Postgres to run as root.

On the bright side, with some minor tweaking, Postgres can start a fresh database in 300 ms which is plenty fast for tests and you avoid spinning up Docker containers. I ended up using template databases to only spin up the database once per test suite. Each tests then copies the database template for each test in the suite which reduced the setup time per test to ~20 ms.

Instead of using rules_foreign_cc to build Postgres from source with Bazel, I ended up building Postgres outside of Bazel with Docker and zipping it up by target platform (linux|darwin)_(arm64|amd64).

https://www.postgresql.org/message-id/4E0DE1B6.6070600@postn...

Re:In Praise of PostgreSQL by mleonard on Friday August 06, 2021 @06:09AM (#28085181)
Very interesting. Is any of this open source? I'd love to take a look!

I'm guessing it's not open source - as I couldn't find it on your Github account or your company's account. If that's the case, would you be able to create a quick gist with a copy/paste of any of the code you can share? If you have the time I'd appreciate it!

Related links for anyone interested: - dataform uses bazel for ci tests. They builds redis from source, but run postgres as a container. See here: https://www.reddit.com/r/bazel/comments/kcmbwb/how_to_run_se...

Re:In Praise of PostgreSQL by jvolkman on Saturday August 07, 2021 @03:09AM (#28096460)
We pull Postgres from Nix using rules_nixpkgs for our Bazel tests. It works pretty well. I wrote some additional infrastructure that makes it easy to test against different versions of postgres (11, 12, 13 - all available from Nix) using simple Bazel command line options.
Re:In Praise of PostgreSQL by sa46 on Friday August 06, 2021 @06:43PM (#28093627)
Sure, here's sketch of how it works: https://github.com/jschaf/bazel-postgres-sketch
Re:In Praise of PostgreSQL by mleonard on Thursday August 12, 2021 @04:50AM (#28153765)
Amazing thanks so much!
Re:In Praise of PostgreSQL by anarazel on Friday August 06, 2021 @07:30PM (#28094025)
> 1. Postgres doesn't really didn't want to be statically compiled, according to [1].

Right. There's a lot of features that'll flat out not work if you somehow compile it statically. I don't think it's a useful thing to run tests with a version of postgres built like that. Nor does it really solve anything - postgres will still require a bunch of on-disk files.

You shouldn't need have to do so anyway - you can relocate the postgres installation itself when compiled normally. Binaries like postgres will try to find the files they need relative to their own location if not found at the builtin location.

Of course, libraries that PG binaries dynamically link to need to be somewhere in the library path. If you need to adjust that you can do it by adding rpaths to the binaries/libraries to additional locations, so you don't need to adjust LD_LIBRARY_PATH.

Re:In Praise of PostgreSQL by sa46 on Friday August 06, 2021 @07:41PM (#28094101)
I ended up skipping static compilation for the reasons you outlined (not necessary). I packaged everything up in a directory and used LD_LIBRARY_PATH. I linked to a sketch on GitHub in a sibling comment.
Re:In Praise of PostgreSQL by anarazel on Thursday August 05, 2021 @04:26PM (#28079264)
There's a decent bit of optimizations that sqlite can do by virtue of effectively being single-writer that postgres can't without compromising a lot of other workloads. That's e.g. one of (but not the only) the contributing factors to why the per-row overhead in sqlite is smaller than in PG. And of course something like PG won't be embeddable into the address space of an application, which invariably leads to higher latency (even if it still can be low).

WRT "embeddable postgres":

Postgres relies on having multiple processes that collaborate on making database access fast. And it requires there to be only a single instance of postgres that can access the data. There's some inherent increase in difficulty of embedding something like that compared to something with sqlite's architecture.

Until recently PG didn't have a way to provide non-tcp access on windows, which made embedding on windows a bit more problematic. But since Win 10 unix domain sockets are available on windows, so things have gotten better.

I'd guess that after that the fact that a postgres installation consists out of many files, instead of a shared library or two, is the biggest difficulty. Those files are relocatable at least, but it's still far less convenient.

I don't know how much of a relevant factor the layout of the "data directory" is - for some database embedding scenarios it sure is convenient to only have to deal with a file or two. But moving a directory around isn't that much harder...

My guess is that somebody with interest could improve the situation measurably within a reasonable timeframe...

Re:In Praise of PostgreSQL by donarb on Thursday August 05, 2021 @01:24PM (#28076766)
On the Mac at least, there is PostgresApp. A double-clickable application that wraps a PostgreSQL server. Installation takes a minute or two without having to use the command line for compilation.

https://postgresapp.com

Re:In Praise of PostgreSQL by Tostino on Thursday August 05, 2021 @02:26PM (#28077589)
Completely agreed. I would love to be able to use an embedded version of Postgres. I have no interest in SQLite though because of the dynamic typing, reduced feature set, lack of advanced features, etc...
Re:In Praise of PostgreSQL by marcosdumay on Thursday August 05, 2021 @03:48PM (#28078654)
On Linux you don't actually need to install Postgres. For Windows there is this: https://garethflowers.dev/postgresql-portable/

I agree it could be better packaged, but it's actually not impossible to ship a Postgres with your program.

Re:In Praise of PostgreSQL by SahAssar on Friday August 06, 2021 @06:05AM (#28085163)
> On Linux you don't actually need to install Postgres.

What do you mean? It's not like postgres is bundled by default with most distros.

Re:In Praise of PostgreSQL by marcosdumay on Friday August 06, 2021 @09:24AM (#28086810)
You can run it without installing. You can run almost anything on Linux without installing.
Re:In Praise of PostgreSQL by SahAssar on Friday August 06, 2021 @11:01AM (#28088087)
That's true for all OS'es (except iOS & android), if you have the executable you can run it. Installing usually just consists of placing the executable on a specific path and creating some directories to hold data/config/logs. You also often need to consider the dependencies of the application (unless it's statically compiled), so it's a lot easier to use your distros package manager.
Re:In Praise of PostgreSQL by marcosdumay on Friday August 06, 2021 @11:47AM (#28088790)
That's really not true for all applications, and Windows applications tend to require being installed, while Mac ones are all over the place.

Yes, the OS doesn't impose any opinion. It's just a matter of what application developers do, and the developers of Linux applications tend to write code that doesn't require installing. As an example, there's Postgres :)

Re:In Praise of PostgreSQL by SahAssar on Friday August 06, 2021 @03:46PM (#28091925)
I still don't get what you mean (or exactly what you mean when you say "installing"), Postgres can be a simple executable on OSX and Windows and on linux it is usually "installed" because it needs to setup a data directory, user/group, config directory and so on.

There is nothing about linux that makes postgres more or less portable than on windows or osx, and I'd be interested if you have any examples of postgres being used in a non-packaged way (outside of development tools like postgresapp.com).

Besides that, one of the strengths of most linux distros is that they provide a centralized way to install/upgrade packages like apt/yum/dnf/pacman and don't have to rely on third party tools like homebrew.

Re:In Praise of PostgreSQL by hitekker on Thursday August 05, 2021 @02:08PM (#28077362)
The "mode" you wish for is a rearchitecture of PostgreSQL. Embedded and client-server DBs are two distinct systems.
Re:In Praise of PostgreSQL by 7952 on Thursday August 05, 2021 @04:13PM (#28079052)
Why though? Naively it would be possible to bundle postgres and have your app connect on localhost. What would be wrong with doing that?
Re:In Praise of PostgreSQL by handrous on Thursday August 05, 2021 @05:59PM (#28080526)
You could do it, but you'd be paying (in complexity, resource use, and bundle size) for a bunch of features and optimizations you don't need, and it'd be tuned for a totally different use case than occasional access by one local process.