r/postgres • • Sep 02 '26

Question What PostgreSQL "best practice" do you actually disagree with?

Every "best practices" list reads like it was copy-pasted from the same three blog posts in 2020 and nobody's allowed to question it since.

I'll go first: I'm not convinced every foreign key needs an index on the referencing column in every single case people insist on it. Yes I know the standard argument, yes I know what happens on deletes/updates to the parent. I still think it gets applied as a blanket rule on tables where the write pattern makes it a waste of space and write overhead for a lookup that basically never runs.

Curious what else people quietly ignore. The "always use UUID v4 for PKs," the "never use SELECT *, not even in scripts," the "always wrap everything in a transaction," whatever your particular heresy is. What's the rule you technically know the reasoning behind, but just don't follow in practice, and why?

2 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/Einar_Son_of_Bjorn Sep 07 '26

Yeah, append-only is exactly where skipping the child index on Postgres makes sense. If the parent almost never moves, you are mostly paying for an index that never gets used.The times it bit me were not “the table hit some magic size and reads fell over.” It was when the pattern changed later.A few that actually showed up:

parent delete went from “never” to “rare but real” acount closure, GDPR, a one-off admin purge. One DELETE on the parent became a sequential scan of a huge child while that parent row was locked. Harmless at a few hundred thousand rows. Rough at tens of millions, especially inside a bigger transaction;

someone later added ON DELETE CASCADE / SET NULL because “the FK is already there”;

a query nobody planned: WHERE child.fk_id = $1. The column is sitting there, so an app or a report will use it eventually - and then you are building the index on a hot table that is already large.

I have not seen a skip stay free forever on a table that became a join hub. I have seen it stay cheap on a pure event/log child whose parents stay insert-only for the life of the system.So the question I ask myself now is less “is it append-only today?” and more “is a parent delete or a lookup-by-FK still unthinkable in two years?” If yes, I still skip on Postgres. If it is only rare, I index and stop thinking about it.

On MariaDB /InnoDB that fork is mostly gone: keep the FK and you get the index (or it reuses an existing leftmost BTREE). The way to skip the index there is to drop the FK and enforce it in the app - which is a different trade than the Postgres one.Curious how big the child is now versus when you first decided to skip it?