Live data from Hacker News

Ways to shoot yourself in the foot with Postgres

philbooth.me

41–50 of 329 posts

Re: Ways to shoot yourself in the foot with Postgres

#41
post #11

Postgres doesn't automatically create indexes for foreign keys. This may come as a surprise if you're more familiar with other databases, so pay attention to the implications as it can hurt you in a few ways. I don't know of any database system that does this. In the case for SQL Server, the foreign keys usually get added by the ORM layer (Entity Framework migrations if you're using dotnet).

MySQL InnoDB does I believe...

It will create an index if no existing index meets the requirements of the foreign key.

Re: Ways to shoot yourself in the foot with Postgres

#42
post #28
post #26

"2. Push all your application logic into Postgres functions and procedures" Why are functions and procedures (an abstraction layer at db layer) considered harmful to performance when the same abstraction layer will be required at the application layer (introducing out of process overhead and possibly network traffic)? I don't agree with this advice. (Or I don't understand it.)

It is always more easier to scale horizontally at application layer (just adding more servers) than at database layer (which involves syncing data between multiple database instances).

In my experience more often than not, Postgres performance problems aren't really caused by the database, but either badly designed schemas or queries. For a lot of developers, the thinking goes that 10s of millions of rows sounds like a lot like big data, so they must start building microservices, distributed systems, use K/V stores and horizontally scale a la Google, whereas their entire dataset could actually fit in RAM of a single server and they could avoid the majority of the complexity if they just scaled vertically, which is usually much, much easier.

Re: Ways to shoot yourself in the foot with Postgres

#43
post #39

I’d add ’not reading the table of contents of the manual’ to the list. I’ve probably worked with hundreds of people now who use a database daily either in code or just to explore data and can count on two hands (optimistically…) the number of folks who actually read the fine manual in any other way than googling something specific. Pro tip: read it so you know what to google for!

This. https://www.postgresql.org/docs/current/

Re: Ways to shoot yourself in the foot with Postgres

#44

Two years ago I moved to a new company using Postgres as THE relational db, coming from years of Sql Server I found poor query plan issues troubleshooting tools. Anyway, I don't know if it's the same in Postgres, but in Sql Server an OR condition like that could kill your performance quite easily in a relatively complex query, often I had to refactor my query to a UNION (usually with ALL to avoid a distinct step, but…

Similar in postgres, depending on version.

SQL Server is a damn fine DB if you can afford it. Highly recommended.

Re: Ways to shoot yourself in the foot with Postgres

#45
post #39

I’d add ’not reading the table of contents of the manual’ to the list. I’ve probably worked with hundreds of people now who use a database daily either in code or just to explore data and can count on two hands (optimistically…) the number of folks who actually read the fine manual in any other way than googling something specific. Pro tip: read it so you know what to google for!

It took me too long to understand this. I always felt pressure to get things done so skipped reading the manual. Turns out I would have gotten more done had I just read the manual.

Re: Ways to shoot yourself in the foot with Postgres

#46
post #31
post #28

Earlier quoted context omitted.

It is always more easier to scale horizontally at application layer (just adding more servers) than at database layer (which involves syncing data between multiple database instances).

You can horizontally scale the database directly.

Depends on the scenario

Re: Ways to shoot yourself in the foot with Postgres

#49
post #6

Pertinent: https://wiki.postgresql.org/wiki/Don%27t_Do_This

There's something ironic about having so many features that you have a dedicated page telling users which ones not to use.

To be fair, some of them exist in PostgreSQL because it tries rather hard to conform to the SQL standard.

Re: Ways to shoot yourself in the foot with Postgres

#50
post #6

Pertinent: https://wiki.postgresql.org/wiki/Don%27t_Do_This

There's something ironic about having so many features that you have a dedicated page telling users which ones not to use.

PostgreSQL has been around for almost 27 years (and even longer, if you include the Ingress and Post-Ingress eras). And things, well things, they tend to accumulate, to quote Trent Reznor, heh.

On a related note, one could say that the C++ Core Guidelines[1] at least partially represent such a list. 55 matches for “don't use” and 247 for “avoid”, although not all of them are about language features, obviously.

[1]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

Post reply on HN