Skip to main content

Storage Considerations

Learning Focus

Use this lesson to pick types that keep rows and indexes small without sacrificing correctness.

Concept Overview

Type choices affect:

  • row width (memory + I/O)
  • index size
  • cache efficiency

Practical Guidelines

GoalPrefer
Long-lived PKsbigint identity
Money-like valuesnumeric(p,s) or integer cents
User-facing stringstext
Optional metadatajsonb (only for flexible attributes)

Notes on Large Values (TOAST)

PostgreSQL can store large text/bytea/jsonb values out-of-line using TOAST.

Even with TOAST, wide rows can still impact performance through extra fetches.


Best Practices

  • Use the smallest type that fits the domain.
  • Avoid storing large blobs in hot tables.
  • Normalize core fields; use JSONB only for flexible fields.

What's Next