news.volyx.in

Ways to shoot yourself in the foot with Postgres (philbooth.me)

743 points by philbo · 1224 days ago · 268 comments on HN

Article summary

The article discusses common mistakes to avoid when using PostgreSQL, including keeping the default value for work_mem, pushing application logic into Postgres functions and procedures, and using lots of triggers. These mistakes can lead to performance issues and scalability problems. The article provides tips and best practices for avoiding these mistakes and optimizing PostgreSQL performance. By being aware of these potential pitfalls, developers can write more efficient and scalable code.

Main themes

  • PostgreSQL optimization
  • database performance
  • query planning
  • indexing
  • trigger usage
  • denormalization
  • materialized views
  • error handling

What commenters say

  • Some database systems automatically create indexes for foreign keys, but PostgreSQL does not, which can lead to performance issues if not handled properly.
  • Using EXPLAIN ANALYZE on production data can be necessary in some cases, despite the potential risks.
  • Postgres query planner can sometimes choose inefficient plans, but this can be mitigated with proper indexing and configuration.
  • Denormalizing data and using materialized views can improve query performance, especially for complex queries.
  • The IS NOT DISTINCT FROM operator does not use indexes, which can lead to performance issues, but this can be worked around by using explicit null checks.
  • Proper use of triggers and custom error codes can improve database performance and debugging.
  • Some developers prefer a simpler query planner that requires more explicit configuration, while others appreciate the flexibility of Postgres' query planner.