AI Hints
Home›PostgreSQL Tutorial›Job Queues, Mistakes and Alternatives
PostgreSQL · Lesson 104 of 120

Common Mistakes

Learn from others.

⏱ 2 min read▶ Video at 1:34:28🎓 Free
Watch this lesson in the PostgreSQL courseWatch on YouTube ↗Full PostgreSQL course

Most Postgres trouble comes from the same small set of mistakes. Knowing them early saves a lot of late nights.

  • Same mistakes
  • Every team
  • Avoid them

Mistakes and fixes

Storing money in floating point. Timestamps without time zones. No indexes on foreign keys. Long running transactions that block vacuum. And opening a new connection for every request.

MistakeFix
float for moneynumeric
timestamp, no zonetimestamptz
Unindexed FKsindex them
Long transactionskeep short
Connect per requestuse a pool

Quick check

Quick check. A shop stores prices, and totals must be exact to the cent. Which type should the price column use? Pause and choose. The answer is C, numeric. It stores decimals exactly, while double precision can drift.

Quick check
Best type for an exact price

Summary

Use numeric for money, timestamptz for moments, index foreign keys, keep transactions short, and pool connections. Next, how Postgres compares with other databases.

Key takeaways
  • numeric
  • timestamptz
  • Pools
Next up: Postgres vs Other Databases — pick the right tool