How do you optimize PostgreSQL?
Short answer
Start with schema design — normalized tables, foreign keys, and indexes on the columns used in WHERE, JOIN, and ORDER BY — then profile queries with EXPLAIN ANALYZE and add targeted indexes.
Index what you query: foreign-key columns, status filters, and timestamps used in range queries. Avoid over-indexing, which slows writes.
Use EXPLAIN ANALYZE to find sequential scans on hot paths and confirm indexes are actually used.
For a tenant-based system, choose the isolation model that matches your scale — the restaurant SaaS uses database-level tenant isolation (a schema per tenant) to keep multi-tenant queries fast and clean.
Add connection pooling for many concurrent clients, use prepared statements, and cache hot read-heavy data in Redis to keep the database focused on writes and complex joins.