TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PostgreSQL Best Practices

72 pointsby lemonwaterlime3 months ago

9 comments

tefkah3 months ago
shallow AI ass article, i’m betting i’d get the exact same if i’d ask an llm to write me an article about postgres best practices
评论 #42994840 未加载
Kwpolska3 months ago
&gt; Here are recommended naming practices:<p>Recommended by whom, based on what?<p>Everything in this article seems to be blogspam, with zero links, sources, or rationales for the decisions provided.
cube22223 months ago
Regarding streaming replication, these days you might want to also consider a “disaggregated storage-compute” setup, like AWS Aurora, or Neon (which is open-source I believe).<p>Re partial indexes - those are great, though you have to be careful to keep them updated as your queries evolve. E.g. if you have a partial index on a set of enum values, you should make sure to check and potentially update it whenever you add a new enum variant.
nakovet3 months ago
The access control portion is not clear to me: `current_user_organization_id()` where is this reading from? We tried using `set_config` <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;functions-admin.html" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;functions-admin.html</a> and it was incredibly slow, it was not designed for how we were using which was included connection pooling and each query ran a difference &quot;current_user_id&quot; set_config.
评论 #42994345 未加载
jitl3 months ago
Plural table names are silly, I will die on this hill.
评论 #43000586 未加载
VWWHFSfQ3 months ago
You will find major performance improvements by using `include` with your indexes. For instance, on something trivial like counting votes on a blog post:<p><pre><code> create table post_vote ( post_id bigint not null references posts (id), user_id bigint not null references users (id), amount smallint not null, primary key (post_id, user_id) include (amount) ); select sum(amount) from post_vote where post_id = :&#x27;post_id&#x27;; </code></pre> Upvotes are 1, downvotes are -1. This will be a nearly instantaneous index-only scan summing the amount values.
评论 #42995659 未加载
评论 #42994743 未加载
1a527dd53 months ago
I&#x27;m amazed that this has reached the almost-top of HN.<p>It&#x27;s a very confused article that (IMO) is AI Slop.<p>1. Naming conventions is a weird one to start with, but okay. For the most part you don&#x27;t need to worry about this with PKs, FKs, Indices etc. Those PG will automatically generate for you with the correct syntax.<p>2. Performance optimization, yes indices are create. But don&#x27;t name them manually let PG name them for you. Also, where possible _always_ create the index concurrently. This does not lock the table. Important if you have any kind of scale.<p>3. Security bit of a weird jump as you&#x27;ve gone from app tier concern to PG management concerns. But I would say RLS isn&#x27;t worth it. And the best security is going to be tightly control what can read and write. Point your reads to a read only replica.<p>4. pg_dump was never meant to be a backup method; see <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;message-id&#x2F;flat&#x2F;70b48475-7706-4268-990d-fd522b038d96%40eisentraut.org" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;message-id&#x2F;flat&#x2F;70b48475-7706-426...</a><p>5. You don&#x27;t need to schedule VACUUM or ANALYZE. PG has the AUTO version of both.<p>6. Jesus, never use a DEFAULT value on a large table that causes a table rewrite which will cause you downtime. Don&#x27;t use varchar(n) <a href="https:&#x2F;&#x2F;wiki.postgresql.org&#x2F;wiki&#x2F;Don%27t_Do_This#Don.27t_use_char.28n.29" rel="nofollow">https:&#x2F;&#x2F;wiki.postgresql.org&#x2F;wiki&#x2F;Don%27t_Do_This#Don.27t_use...</a><p>This is an awful article.
评论 #42994898 未加载
评论 #42997453 未加载
评论 #42995283 未加载
tfeldmann3 months ago
I’m struggling naming my views. Any recommendations? Same naming as tables?
评论 #42994318 未加载
评论 #42994751 未加载
nick_3 months ago
Why is snake_case recommended? What advantage(s) does it provide?
评论 #42994418 未加载
评论 #42994699 未加载
评论 #42994379 未加载