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
| Goal | Prefer |
|---|---|
| Long-lived PKs | bigint identity |
| Money-like values | numeric(p,s) or integer cents |
| User-facing strings | text |
| Optional metadata | jsonb (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.