< Back to notes

Browse 15 notes tagged database.

#database

PostgreSQL backups: what pg_dump, WAL, and PITR actually do

Use an accidental order deletion to understand RPO and RTO, SQL versus custom archive restore tools, forward WAL replay, and PITR stopping points and restore checks.

Supabase RLS Beyond the Policy UI: Make Authorization SQL Testable

Keep Supabase RLS, least-privilege grants, operation-specific policies, and allow-or-deny SQL tests in migrations so every environment can replay and review them.

PostgreSQL RLS is not an automatic WHERE clause: four boundaries for multi-tenant data

Use PostgreSQL Row-Level Security for a shared table by separating GRANTs from policies, existing rows from proposed rows, and caller identity from view or function ownership.

PgBouncer does not make PostgreSQL infinite: budget connections before choosing a pool mode

Use the boundaries between connections, sessions, and transactions to reason about PostgreSQL connection budgets, PgBouncer modes, session-state compatibility, and `pg_stat_activity`.

Why does the next page repeat a row? OFFSET and keyset pagination

Trace five rows through OFFSET and keyset pagination, then connect compound cursors to B-tree indexes, NULL handling, and the limits of changing data.

A schema migration is not one SQL statement: expand, backfill, and observe before you contract

A PostgreSQL schema migration must account for existing rows, older workers, and newly deployed code. Use expand, repeatable backfills, and evidence about locks, indexes, and constraints before removing an old path.

Do not add an index first: use EXPLAIN, statistics, and ANALYZE to see what PostgreSQL is guessing

PostgreSQL chooses query plans from estimated costs. Compare EXPLAIN estimates with real execution before deciding whether statistics, query design, or an index needs to change.

Indexes follow query shape, not a column checklist

A PostgreSQL index earns its cost only when a real query's filters, ordering, result size, and write workload justify another maintained data structure.

Transaction Boundaries for Orders, Inventory, and ACID

An order can touch inventory, orders, and payment records. A transaction keeps database changes all-or-nothing; it cannot unsend an email or replace constraints and concurrency design.

Before JOIN Syntax, Count the Relationship

Decide what one result row means and whether unmatched data stays first. Then choose INNER JOIN or LEFT JOIN without mistaking normal fanout for duplicates.

A SELECT Needs Four Decisions: Columns, Rows, Order, Limit

A reliable SQL query does more than retrieve data: name the columns, filter with WHERE, define an order with ORDER BY, then cap the result with LIMIT.

A Database Is Not a JSON Blob: Let Constraints Protect Data

Tables, keys, and constraints form a shared data contract. Frontend validation improves UX; the database must reject impossible writes.

PostgreSQL SKIP LOCKED: Job Queue, Not Magic Broker

SKIP LOCKED can claim jobs without worker contention, but reliable delivery still needs short transactions, leases, retries, idempotency, and an exit plan.

PostgreSQL 18 Skip Scan: The Leftmost Rule, Revisited

PostgreSQL 18 can reuse a multicolumn B-tree when the leftmost column is not filtered. The win is real, but cardinality and query plans still decide.

UUIDv7 for Primary Keys: Better, Not Universal

UUIDv7 improves index locality in SQLite and PostgreSQL, but 128-bit keys still cost more than bigint. Use it when distributed ID generation is required.