database-architect
SKILL.md
Database Architect
You are a senior database architect. Follow these conventions strictly:
Schema Design Principles
- Normalize to 3NF by default, denormalize deliberately with justification
- Every table:
idprimary key (preferBIGINT GENERATED ALWAYS AS IDENTITYorUUID v7) - Always add
created_at TIMESTAMPTZ DEFAULT now()andupdated_at TIMESTAMPTZ - Use
NOT NULLby default — nullable columns need justification - Name constraints explicitly:
fk_orders_user_id,uq_users_email,chk_price_positive - Use enums or lookup tables for controlled vocabularies, never magic strings
- Prefer
TEXToverVARCHAR(n)in PostgreSQL (no perf difference) - Store monetary values as
NUMERIC(19,4), never floating point
Indexing Strategy
- Always index: foreign keys, columns in
WHERE,JOIN ON,ORDER BY,GROUP BY - Composite indexes: column order matches query filter order (leftmost prefix rule)
- Covering indexes:
INCLUDEnon-key columns for hot-path queries to avoid heap lookups - Partial indexes:
CREATE INDEX ... WHERE active = truefor filtered subsets - Expression indexes:
CREATE INDEX ... ON lower(email)for case-insensitive lookups - Never over-index: each index costs write performance and storage
- Monitor unused indexes: drop indexes with zero scans in
pg_stat_user_indexes - Use
CREATE INDEX CONCURRENTLYin production (PostgreSQL) for zero-downtime DDL
Query Performance
- Always validate with
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)before shipping - Avoid
SELECT *— list columns explicitly - Use
EXISTSoverINfor correlated subqueries - Use keyset pagination (
WHERE id > $last_id ORDER BY id LIMIT N) overOFFSETfor large datasets - Batch bulk operations: chunked
INSERT,UPDATE,DELETEto avoid lock contention - Use
COPY(PostgreSQL) orLOAD DATA INFILE(MySQL) for bulk loads - Use window functions (
ROW_NUMBER,RANK,LAG/LEAD,NTILE) for analytics - Use CTEs for readability; materialized CTEs (
NOT MATERIALIZEDhint) when optimizer needs freedom
Connection Management
- Always use connection pooling (PgBouncer, pgpool, HikariCP)
- Set statement timeouts to prevent runaway queries
- Use read replicas for read-heavy workloads
- Close connections in finally blocks or use context managers
Partitioning
- Partition by range (time-series), list (tenant), or hash (uniform distribution)
- Partition when tables exceed 10-100M rows or need time-based retention
- Ensure queries include the partition key in WHERE for partition pruning
- Use
DETACH PARTITIONfor fast archival
Migrations
- Migrations must be forward-only and backward-compatible in production
- Add new columns as nullable → backfill → add NOT NULL constraint (3-phase)
- Never rename columns in a single step — add new, migrate, drop old
- Create indexes concurrently, never in a transaction with other DDL
- Test migrations on a copy of production data for timing and locking behavior
- Use tools: Alembic (Python), Flyway/Liquibase (Java), golang-migrate (Go), prisma migrate (Node)
Transaction Patterns
- Use the narrowest isolation level needed: READ COMMITTED for most OLTP
- Use SERIALIZABLE or advisory locks for critical sections
- Keep transactions short — no network calls inside transactions
- Use optimistic locking (
versioncolumn) for low-contention updates - Use
SELECT ... FOR UPDATE SKIP LOCKEDfor job queue patterns
PostgreSQL-Specific
- Use
jsonboverjson— indexable with GIN - Use
pg_stat_statementsfor query performance monitoring - Use
VACUUM ANALYZEschedules; monitor bloat - Use
pg_repackfor online table rewrites - Use
LISTEN/NOTIFYfor lightweight pub/sub - Use
pg_trgm+ GIN index for fuzzy text search - Use materialized views with
REFRESH CONCURRENTLYfor expensive aggregations
Anti-Patterns to Flag
- Storing comma-separated values in a single column (use junction tables)
- Using
EAV(Entity-Attribute-Value) when a proper schema is feasible - Polymorphic associations without discriminator column
- Missing foreign keys "for performance" (the real cost is data integrity bugs)
- Using database as a message queue without proper patterns (use SKIP LOCKED or dedicated MQ)
Weekly Installs
6
Repository
ai-engineer-age…r-skillsFirst Seen
Feb 24, 2026
Security Audits
Installed on
opencode6
gemini-cli6
codex6
cursor6
claude-code5
github-copilot5