News for hackers. Stuff that matters.
Re:Things I hate about PostgreSQL (2020) by rattray on Tuesday April 06, 2021 @08:56AM (#26711193)
Another recent Postgres-complaint post from one of the best engineers I've worked with: https://blog.nelhage.com/post/some-opinionated-sql-takes/

Quoting his conclusion:

> As for Postgres, I have enormous respect for it and its engineering and capabilities, but, for me, it’s just too damn operationally scary. In my experience it’s much worse than MySQL for operational footguns and performance cliffs, where using it slightly wrong can utterly tank your performance or availability. … Postgres is a fine choice, especially if you already have expertise using it on your team, but I’ve personally been burned too many times.

He wrote that shortly after chasing down a gnarly bug caused by an obscure Django/Postgres crossover: https://buttondown.email/nelhage/archive/22ab771c-25b4-4cd9-...

Personally, I'd still opt for Postgres every time – the featureset is incredible, and while it may have scary footguns, it's better to have footguns than bugs – at least you can do something about them.

Still, I absolutely wish the official Postgres docs did a better job outlining How Things Can Go Wrong, both in general and on the docs page for each given feature.

Re:Things I hate about PostgreSQL (2020) by paulryanrogers on Tuesday April 06, 2021 @09:35AM (#26711555)
It's interesting how personal scars can entrench ones perspective. After MySQL 8's renaming-table-will-crash-server bug I'm reluctant to use it for new projects.
Re:Things I hate about PostgreSQL (2020) by aaron-santos on Tuesday April 06, 2021 @11:44AM (#26713264)
In any sufficiently large dev team the technology choices trend toward zero. Because everyone has their "I will not work with this tech after dealing with its nasty bug."
Re:Things I hate about PostgreSQL (2020) by paulryanrogers on Tuesday April 06, 2021 @12:53PM (#26714246)
Indeed. And products can get better and worse over time. If there's a consistent pattern of critical bugs at least with FOSS there is the possibility of forks and 3rd party patches.
Re:Things I hate about PostgreSQL (2020) by Corrado on Wednesday April 07, 2021 @02:55AM (#26721283)
Agreed! My personal bias against a system depends on if it failed at it's primary purpose or not. I've had a lot of things fail in a lot of ways and I'm generally pretty forgiving, but there are some things that are just inexcusable. Some examples:

* A popular (at the time) version control system started to silently overwrite files when it ran out of disk space. We discovered this when we retrieved source code that had parts of another file in it.

* A UPS vendor had a product that tested the battery by turning off the power. When the battery ultimately failed our servers were powered off automatically. This happened randomly about every 3 weeks (usually on a weekend evening). It took us months to find the cause.

I can't come back from these problems. So, if the system is a bit slow or crashes sometimes or has other weird problems, I'm OK with that. If it bites me specifically where it's supposed to protect me, it's out, forever.

Re:Things I hate about PostgreSQL (2020) by jrockway on Tuesday April 06, 2021 @05:32PM (#26717642)
I'm personally guilty of this mindset, but it's something I'm working on. After you get burned by a system, you know of the bug, and you can fix it. But the instinct is to switch to a new system, or to rewrite the system. That does get rid of all the bugs in the old system! But, in the process you've replaced them with brand new bugs that nobody has seen or heard from, until they decide to crawl into your mouth while you're asleep and you wake up in a panic. It's bugs all the way down, folks... this is software we're dealing with!

I think sendmail is the classic example of a program with so many bugs it had to be rewritten from scratch, and many people did. All of those alternatives, even qmail (widely debated: https://www.qualys.com/2020/05/19/cve-2005-1513/remote-code-...), ended up with a bug or security problem too. And they seem to have even fixed sendmail. It's still around and it doesn't take down the whole Internet every three weeks anymore. Wow! Sometimes there are just a million bugs, and you fix all one million of them, and then there aren't any more bugs.

Re:Things I hate about PostgreSQL (2020) by hvidgaard on Wednesday April 07, 2021 @03:03AM (#26721315)
In reality, the smart engineering choice is to know exactly what you are expecting from a specific system, and test it. Bugs, mistakes and even cosmic rays happen, so you must specifically test that it works. If you have a backup power system, test it.
Re:Things I hate about PostgreSQL (2020) by citrin_ru on Wednesday April 07, 2021 @11:14AM (#26726102)
sendmail is not a good example of a bad rewrite: 1st qmail is no more rewritten sendmail than Linux is rewrittnen Unix - qmail/exim/postfix just different software for the same use case. 2dn many other MTA (e. g. Postfix) managed to maintain much lower amount of security vulnerabilities than sendmail.
Re:Things I hate about PostgreSQL (2020) by psanford on Tuesday April 06, 2021 @06:36PM (#26718253)
> It's still around and it doesn't take down the whole Internet every three weeks anymore.

Maybe that's because the vast majority of email no longer goes through sendmail.

Re:Things I hate about PostgreSQL (2020) by oauea on Tuesday April 06, 2021 @10:07AM (#26711909)
As long as mysql can't run ddl statements in a transaction it's worthless as far as I'm concerned.

Also the thing where they (used to?) silently truncate your data when it wouldn't fit a column is absolutely insane. I'll take operational footguns over losing half my data every damn time.

Re:Things I hate about PostgreSQL (2020) by setr on Tuesday April 06, 2021 @03:30PM (#26716316)
Till v8.0.16 mysql used to accept and then just ignore check constraints

I've never been so offended by a technology as the day I discovered that; it's not a misfeature and its not a bug -- only pure malice could have driven such a decision

Re:Things I hate about PostgreSQL (2020) by zodiakzz on Tuesday April 06, 2021 @05:13PM (#26717452)
Don't forget the 3-byte encoding they invented and call it 'utf8'.
Re:Things I hate about PostgreSQL (2020) by spiralx on Thursday April 08, 2021 @05:39AM (#26736836)
I remember reading the MySQL Gotchas page back in the 2000s and that leaping out as a particularly egregious issue. It fit in with their whole ethos of "databases don't need transactions and users don't need errors" around that time though, which put me off for life.
Re:Things I hate about PostgreSQL (2020) by lokedhs on Tuesday April 06, 2021 @10:16AM (#26712019)
I'm definitely no fan of mysql. I have, like many others, been scarred by its misfeatures. However, not having DDL in transactions isn't really a barrier for being useful. Oracle doesn't have transactional DDL either, and say what you will about the company, the product itself has proven itself.
Re:Things I hate about PostgreSQL (2020) by jhgb on Tuesday April 06, 2021 @03:29PM (#26716303)
But Firebird does have it, too. I find it funny how supposedly top products sometimes lack the most basic features.
Re:Things I hate about PostgreSQL (2020) by stepbeek on Tuesday April 06, 2021 @10:12AM (#26711975)
The lack of ddl in a transaction is what scared me away too. Having to manually clean up after a failed migration just felt like something I shouldn't be thinking about.
Re:Things I hate about PostgreSQL (2020) by skunkworker on Tuesday April 06, 2021 @03:09PM (#26716029)
As nice as having DDL in a transaction is, once you get to scale this isn't used as you'll be doing index creation concurrently which cannot be done inside a DDL transaction.
Re:Things I hate about PostgreSQL (2020) by carlos_rpn on Tuesday April 06, 2021 @10:13AM (#26711981)
They don't truncate data anymore, unless you enable it in the configuration (it's disabled by default). Invalid data (0000-00-00) is also not accepted anymore.
Re:Things I hate about PostgreSQL (2020) by Foobar8568 on Tuesday April 06, 2021 @10:39AM (#26712320)
MySQL is as advanced as Oracle on this topic (DDL in transaction), unless Oracle has changed in the recent years.
Re:Things I hate about PostgreSQL (2020) by jeltz on Tuesday April 06, 2021 @12:08PM (#26713616)
Which means equally useless. I agree with him about transactional DDL. Having worked both with it and without it I would never want to go back to MySQL.
Re:Things I hate about PostgreSQL (2020) by Foobar8568 on Tuesday April 06, 2021 @02:48PM (#26715749)
I have never said that it was useful :o I work with SQL Server, and I have been always amazed that DDL aren't transactional in Oracle. And it's supposed to be a "serious" database. That and the empty string being equals to NULL, but I think they 180 on that point in the recent years.
Re:Things I hate about PostgreSQL (2020) by jbluepolarbear on Tuesday April 06, 2021 @10:13AM (#26711982)
They’re so right about performance gotchas. I worked on a large Java project a few years back and they were transitioning from MySQL to Postgres, after the upgrade performance was abysmal. I then spent the next 5 months optimizing queries. A lot of the issues were inner joins and how MySQL and Postgres handled lookups in inner joins differently. I would still pick Postgres over MySQL because the tools and features around it are too very good.
Re:Things I hate about PostgreSQL (2020) by runeks on Tuesday April 06, 2021 @12:00PM (#26713495)
Devil’s advocate: could it simply be that someone spent 5 months optimizing queries for MySQL before switching to Postgres? Such that Postgres performance isn’t “worse”, it just doesn’t plan queries in the same way that MySQL does.
Re:Things I hate about PostgreSQL (2020) by jbluepolarbear on Tuesday April 06, 2021 @01:56PM (#26715151)
It was definitely that. The queries were built to take advantage of MySQL features.I joined after they just switched and was told to optimize queries. Was a pretty toxic job, I was hired work on streaming media systems (like Hulu, ESPN, etc) but instead they had me doing query optimizations. I quit after 5 months. I was never able talk to my boss once, he avoided me and was always too busy.
Re:Things I hate about PostgreSQL (2020) by Shorel on Friday April 09, 2021 @08:51AM (#26749886)
That's the kind of job I enjoy doing.

It is just not sexy and some startup rejected me when I said that's what I do.

Re:Things I hate about PostgreSQL (2020) by nomel on Tuesday April 06, 2021 @08:52PM (#26719296)
The purpose of a query engine is so I don't have to think about this stuff. Computers are supposed to do work for me, no the other way around, dangit!
Re:Things I hate about PostgreSQL (2020) by twic on Tuesday April 06, 2021 @12:11PM (#26713654)
My experience was the opposite - a Java app running on MySQL that had painfully slow joins, that immediately got much faster on porting to PostgreSQL!
Re:Things I hate about PostgreSQL (2020) by rzwitserloot on Wednesday April 07, 2021 @08:54AM (#26724126)
> it’s much worse than MySQL for operational footguns and performance cliffs

As wikipedians would say, [citation needed].

The post you link to concludes with:

> Operating PostgreSQL at scale requires deep expertise

and

> I hate performance cliffs

However, both of these statements are true for _any_ major SQL-based DB engine available, including MySQL.

As the post itself shows, psql is at least doing its job in guaranteeing consistency of the data, and has tools to figure out what is going on, which is absolutely crucial when 'operating at scale'.

In other words, yeah, you need deep expertise. However, no, it's not 'much worse' than MySQL for operational footguns. MySQL has a ton of footguns just the same.

Re:Things I hate about PostgreSQL (2020) by rattray on Tuesday April 06, 2021 @10:59AM (#26712593)
Does anyone know of a quality, comprehensive book that enumerates all the things to watch out for and problems to proactively prevent when operating Postgres at scale?
Re:Things I hate about PostgreSQL (2020) by eor on Tuesday April 06, 2021 @03:56PM (#26716628)
It's not a book, but Christophe Pettus' blog (https://thebuild.com/blog) has a lot of really good information. In particular, his talk "Breaking PostgreSQL at Scale" goes through the problems you run into as you hit different levels of scale (https://thebuild.com/presentations/2019-fosdem-broken.pdf)
Re:Things I hate about PostgreSQL (2020) by rattray on Tuesday April 06, 2021 @04:21PM (#26716890)
Thanks! Very helpful, that talk looks like a (very) condensed version of what I was looking for.

It looks like the video for that talk is here: https://www.youtube.com/watch?v=XUkTUMZRBE8

Re:Things I hate about PostgreSQL (2020) by twunde on Tuesday April 06, 2021 @06:33PM (#26718218)
FYI, for anyone interested Pettus does consulting work as the founder of https://pgexperts.com/. Highly recommend working with him if you need a postgres DBA.
Re:Things I hate about PostgreSQL (2020) by gshulegaard on Tuesday April 06, 2021 @07:00PM (#26718435)
Thanks for that! Been doing a lot of Postgres work but first time seeing that slide deck.
Re:Things I hate about PostgreSQL (2020) by gshulegaard on Tuesday April 06, 2021 @06:49PM (#26718370)
Sorry for the long, rambling comment. After I wrote it I wasn't sure it added much, but since I invested so much time writing it I figured someone might find something in it useful so in that off chance I am posting it.

---

Those were really interesting reads, and it's obvious to me that the author is well experienced even if I find myself at odds with some of the points and ultimate conclusion. To be explicit, there _are_ points which resonated strongly with me.

I am by no means an expert, and fairly middling in experience by any nominal measure, but I _have_ spent a significant portion of my professional experience scaling PostgreSQL so I thought I would throw out my $0.02. I have seen many of the common issues:

- Checkpoint bloat

- Autovacuum deficiencies

- Lock contention

- Write amplification

and even some less widely known (maybe even esoteric) issues like:

- Index miss resulting in seq scan (see "random_page_cost" https://www.postgresql.org/docs/13/runtime-config-query.html)

I originally scaled out Postgres 9.4 for a SaaS monitoring and analytics platform, which I can only describe as being a very "hands on" or a manual process. Mostly because many performance oriented features like:

- Parallel execution (9.6+) (originally limited in 9.6 and expanded in later releases)

- Vacuum and other parallelization/performance improvements (9.6+)

- Declarative partitioning (10.0) (Hash based partitions added in 11.0)

- Optional JIT compiling of some SQL to speed up expression evaluation (11.0)

- (and more added in 12 and 13)

Simply didn't exist yet. But even without all of that we were able to scale our PostgreSQL deployment to handle a few terabytes of data ingest a day by the time I left the project. The team was small, between 4-7 (average 5) full time team members over 3 years including product and QA. I think that it was possible--somewhat surprisingly--then, and has been getting steadily easier/better ever since.

I think the general belief that it is difficult to scale or requires a high level of specialization is at odds with my personal experience. I doubt anyone would consider me a specialist; I personally see myself as an average DB _user_ that has had the good fortune (or misfortune) to deal with data sets large enough to expose some less common challenges. Ultimately, I think most engineers would have come up with similar (if not the same) solutions after reading the same documentation we did. Another way to say this is I don't think there is much magic to scaling Postgres and it is actually more straight forward than common belief suggests; I believe there is a disproportionate amount of the fear of the unknown rather than PostgreSQL being intrinsically more difficult to scale than other RDBMS's.

The size and scope of the PostgreSQL feature set can make it somewhat difficult to figure out where to start, but I think this is a challenge for any feature-rich, mature tool and the quality of the PostgreSQL documentation is a huge help to actually figuring out a solution in my experience.

Also, with the relatively recent (last 5 years or so) rise of PostgreSQL horizontal-scale projects like Citus and TimescaleDB I think it is an even easier to scale PostgreSQL. Most recently, I used Citus to implement a single (sharded) storage/warehouse for my current project. I have been _very_ pleasantly surprised by how easy it was to create a hybrid data model which handles everything from OLTP single node data to auto-partitioned time series tables. There are some gotchas and lessons learned, but that's probably a blog post in it's own right so I'll just leave it as a qualification that it's not a magic bullet that completely abstracts the nuances of how to scale PostgreSQL (but it does a darned lot).

TL;DR: I think scaling PostgreSQL is easier than most believe and have done it with small teams (< 5) without deep PostgreSQL expertise. New features in PostgreSQL core and tangential projects like Citus and TimescaleDB have made it even easier.

Re:Things I hate about PostgreSQL (2020) by barrkel on Wednesday April 07, 2021 @04:27AM (#26721857)
Don't knock yourself. Doing this work of scaling increases your expertise substantially, and the journey and the hurdles you cross along the way move you several standard deviations beyond the crowd. Specialist is a different term; it's more exclusionary than it is necessarily denoting of expertise. You can specialize in small applications without gaining expertise in scale.
Re:Things I hate about PostgreSQL (2020) by gshulegaard on Thursday April 08, 2021 @02:39PM (#26742214)
I greatly appreciate your positivity!

Experience is a great expertise builder for sure, although I find the more experience I get the more technical expertise I realize I don't have. A bit ironic now that I am thinking about it in those terms.

But I hope my comment made scaling PostgreSQL feel approachable for others who consider themselves non-experts in the area. The message I hoped to build was that non-experts can be successful without trivializing the effort. Which can be a somewhat difficult line to walk.

But thank you regardless.

Re:Things I hate about PostgreSQL (2020) by rattray on Tuesday April 06, 2021 @07:10PM (#26718511)
Thanks :) FWIW I find this level of detail useful.

What do you mean by "Index miss" – index cache miss (ie not in RAM)?

Re:Things I hate about PostgreSQL (2020) by gshulegaard on Tuesday April 06, 2021 @08:21PM (#26719045)
Oh that is a self-coined term...sorry! Basically (as I understand it as a layman) the query planner can "choose" to perform a sequential scan instead of use an index when executing a query. For "normal" sized workloads on "traditional" hardware (like 5400 rpm disk drives) this is a performance gain, but for large data sets it can cripple performance and even lock up a DB.
Re:Things I hate about PostgreSQL (2020) by ptman on Wednesday April 07, 2021 @12:43AM (#26720685)
can you avoid that by tweaking the cost factors in postgres config?
Re:Things I hate about PostgreSQL (2020) by gshulegaard on Wednesday April 07, 2021 @12:53AM (#26720737)
Exactly! Reduce "random_page_cost" down (default is 4) and this becomes a non-issue. It's just one of the less well known things and somewhat difficult to diagnose. What I mean is that what you will see is your database returned rows metric will rapidly climb but rows fetched will hold steady (or decrease). Based on that alone it is a bit of a leap (or at least it was for me at the time) to conclude that the query planner was not using an index on a table that was clearly indexed.

Once you understand what is going on, it makes perfect sense. It's just getting there that is the trick.

Re:Things I hate about PostgreSQL (2020) by LinuxBender on Wednesday April 07, 2021 @10:06AM (#26725160)
Out of curiosity, do these optimizations / calculations find their way into scripts like postgresqltuner [1] or do most DBA's here just apply their own learned optimizations manually?

[1] - https://github.com/jfcoz/postgresqltuner

Re:Things I hate about PostgreSQL (2020) by gshulegaard on Thursday April 08, 2021 @02:30PM (#26742097)
This is the type of thing that I hope make into a tool like postgresqltuner, although I must confess this is the first time I have heard of it (great looking utility though!). I am more of a generalist that happens to have spent time scaling Postgres so I can't comment much on what a "true" DBA would do, but I find myself applying sensible settings in the postgres config for parameters I have used before. This would be more on the "manual" side of your question. To be fair, I think the relatively straightforward nature of PostgreSQL and the great configuration documentation makes this easy once you know a configuration parameter exists.

If I were to skew more of my development cycles to dedicated database management, I think incorporating analytic tools like postgresqltuner would be a must. Although I would probably cross-reference any suggestions with my past experience and dig into Postgres docs on the specific parameters it highlights. Regardless I suspect it would be a valuable source of additional context.