What problem does it solve?
PostgreSQL patterns address common performance pitfalls in database design and query execution, such as inappropriate data types, missing or poorly used indexes, and risky anti-patterns, offering practical guidance to improve reliability and speed.
Core Features & Use Cases
- Data Types: use appropriate types (NUMERIC vs REAL for money, TIMESTAMPTZ vs TIMESTAMP, TEXT for IDs, VARCHAR(255) for emails, BOOLEAN defaults, JSONB for metadata)
- Index Strategy: primary keys and foreign keys should be indexed; use partial unique indexes; index timestamps for time-series workloads
- Query Patterns: parameterized queries, explain analyze for slow queries, limit on list endpoints, and queue processing with FOR UPDATE SKIP LOCKED
- Connection Pooling: pool size and timeouts configurable via environment variables; Neon pooler support
- Anti-Patterns to Avoid: avoid N+1 queries, avoid SELECT *; ensure indexes exist; avoid storing secrets in DB; avoid using real numbers for money
Quick Start
Apply these patterns to your PostgreSQL schema and queries to improve performance and reliability.