databaseEngineering
The day-to-day database craft: indexing, reading EXPLAIN, transactions and isolation, locking, data modeling.
1 item
Indexing — the highest-leverage skill
WHERE, JOIN, ORDER BY, or GROUP BY.(a, b) serves queries filtering on a or a + b, but not b alone. Put the most selective / most-equality-filtered column first.CREATE INDEX ... WHERE status = 'active' is smaller and faster when you almost always query active rows.INCLUDE let an index-only scan return columns without touching the heap.Read EXPLAIN ANALYZE
EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
Seq Scan on a large table in a hot path = missing index (usually).ANALYZE.Nested Loop over many rows is often a sign the planner chose wrong or an index is missing.Transactions & isolation
READ COMMITTED. Use REPEATABLE READ or SERIALIZABLE when you need consistent multi-statement reads, and be ready to retry on serialization failures.Locking & concurrency
SELECT ... FOR UPDATE to lock rows you're about to modify (e.g. decrementing inventory).SELECT ... FOR UPDATE SKIP LOCKED is the classic pattern for a Postgres-backed job queue: each worker grabs the next unlocked row.Data modeling
timestamptz (never naive timestamps), numeric for money (never float), uuid for external IDs, jsonb for flexible/semi-structured data.jsonb is powerful but not a schema replacement — index specific paths with expression or GIN indexes if you query into it.NOT NULL, CHECK, UNIQUE, FKs. The database is your last line of defense against bad data.