Skip to content
Arief Badrus Sholeh
Blog

Postgres notes I keep coming back to

A short reference for indexes, EXPLAIN, and the habits that prevent slow queries in small apps.

1 min readpostgresdatabase

A few notes from running small Postgres databases in production.

Read the plan

sql
EXPLAIN ANALYZE
SELECT * FROM posts WHERE published = true ORDER BY published_at DESC LIMIT 10;

If the plan shows a sequential scan on a large table, an index is usually the answer.

Index what you filter and sort by

  1. Columns in WHERE
  2. Columns in ORDER BY
  3. Foreign keys

Row Level Security stays on for every table, even when the server uses a service key.