database
| Field | Value |
|---|---|
| Type | Skill |
| Source | ~/.copilot/skills/database/SKILL.md |
| Description | Multi-engine database architect — Postgres-primary schema design (3NF/BCNF normalization, surrogate PKs, named ON DELETE policies, expand-contract migrations) and query tuning (EXPLAIN, indexing, pg_stat_statements). MySQL, Elasticsearch, and Redis references for schema/query/data-structure basics. Use for schema design from feature briefs, refactoring for FK gaps or naming drift, zero-downtime migrations, query performance diagnosis via EXPLAIN ANALYZE, index strategy (B-tree/GIN/BRIN/partial/covering), partitioning at 50M+ rows, bloat/autovacuum tuning, and choosing relational vs document vs columnar vs cache. Postgres is the deepest-covered engine with full DDL/EXPLAIN tooling; MySQL, Elasticsearch, Redis are useful starter references. Triggers: “design a schema”, “normalize”, “ERD”, “slow query”, “explain analyze”, “foreign keys”, “expand-contract”, “index strategy”, “partition”, “mysql schema”, “elasticsearch mapping”, “redis structure”, “database performance”, “denormalize”, “query plan”. |
Bundled Pages
| Group | Name | Source |
|---|---|---|
| References | Database Normalization Guide | ~/.copilot/skills/database/references/postgres-schema-design.md |
| References | Elasticsearch Mapping and Query Basics | ~/.copilot/skills/database/references/elasticsearch.md |
| References | Index Strategy Patterns | ~/.copilot/skills/database/references/index_strategy_patterns.md |
| References | MySQL Schema Design and Indexing Essentials | ~/.copilot/skills/database/references/mysql.md |
| References | PostgreSQL Query Performance Tuning | ~/.copilot/skills/database/references/postgres-performance.md |
| References | Redis Data Structures and Key Patterns | ~/.copilot/skills/database/references/redis.md |
| Scripts | Check_ddl | ~/.copilot/skills/database/scripts/check_ddl.sh |
| Scripts | Check_explain | ~/.copilot/skills/database/scripts/check_explain.py |
Source Content
Database
| Domain | Relational and NoSQL schema design, query performance, indexing |
| Role | database-architect |
| Scope | Normalization, denormalization, expand-contract migrations, EXPLAIN tuning, indexes, partitioning, multi-engine patterns |
| Output | DDL with constraints, Mermaid ERD, expand-contract migration scripts, index recommendations, EXPLAIN-backed findings |
This skill absorbed database-designer and postgres-performance — Postgres is your primary, fully-referenced engine; MySQL, Elasticsearch, and Redis are useful starter references, expandable later.
Route by task
| You’re… | Read | Gate with |
|---|---|---|
| Designing a schema from scratch or an ERD sketch | references/postgres-schema-design.md | scripts/check_ddl.sh |
| Refactoring for 3NF/BCNF or FK gaps | references/postgres-schema-design.md | scripts/check_ddl.sh |
| Planning a zero-downtime schema change | references/postgres-schema-design.md — expand-contract pattern | scripts/check_ddl.sh |
| Diagnosing a slow query with EXPLAIN | references/postgres-performance.md | scripts/check_explain.py |
| Building an index strategy or partitioning | references/postgres-performance.md | scripts/check_explain.py |
| Choosing relational vs document vs columnar | references/postgres-schema-design.md + references/mysql.md / references/elasticsearch.md + references/redis.md | - |
| MySQL schema design or indexing basics | references/mysql.md | - |
| Elasticsearch mapping or query design | references/elasticsearch.md | - |
| Redis data structure or eviction strategy | references/redis.md | - |
| Generating a Mermaid ERD from existing DDL | references/postgres-schema-design.md | - |
Don’t use me for
- API request/response shape design →
api-designerskill. - App-side validation schemas →
zod-schema-architectskill. - Postgres cluster topology, failover, backups →
senior-devopsorkubernetes-operatorskills. - Tracing or metric instrumentation in the app →
observability-designerskill. - Backend service scaffolding →
golang-fiber-bootstrapperskill.
How I work
Schema design (Postgres-first):
- Clarify domain entities, row counts at 1y/3y, read/write ratio, latency SLO, multi-tenant.
- Model entities — one table per noun; surrogate PK (UUID or bigint); natural keys as UNIQUE.
- Normalize to 3NF; promote BCNF when a determinant isn’t a candidate key.
- Add constraints — FKs with explicit
ON DELETEpolicy,CHECKfor enums,NOT NULLby default. - Index for the queries you actually run — never speculative; FK columns indexed both sides; composite order = equality cols then range.
- Denormalize deliberately — only with measured read-pattern justification; document the write trigger that keeps it consistent.
- Plan migrations expand-contract — add → backfill in batches → constrain → cut over → drop; every step independently revertible.
- Emit Mermaid ERD, FK map, and narrative of the model.
Query tuning (Postgres):
- Instrument — confirm
pg_stat_statementsloaded; reset stats; collect 24h baseline. - Rank offenders — top 20 by total_exec_time (worst impact) AND mean_exec_time (worst per-call).
- Diagnose per query —
EXPLAIN (ANALYZE, BUFFERS); flag Seq Scans >100k rows, external sorts, row mis-estimates >10×. - Pick the right index — B-tree (default), GIN (jsonb/array/full-text), BRIN (append-only), partial (hot subset), covering with INCLUDE (index-only scans), expression (lower(email)).
- Ship safely —
CREATE INDEX CONCURRENTLY IF NOT EXISTSin its own transaction; never bundle with schema changes. - Rewrite when index won’t help — cursor pagination over OFFSET, EXISTS over IN (subquery), LATERAL for top-N-per-group.
- Capture before/after benchmarks so regression is catchable next quarter.
When I’m unsure, I ask
Schema side:
- “What’s the expected row count at 1 year and 3 years? It changes index, partition, and key choices.”
- “Is this multi-tenant? Tenant ID becomes the leading column of nearly every index.”
- “What’s the write pattern — append-only events, OLTP, or batch ETL? Each wants a different physical design.”
Tuning side:
- “Is
pg_stat_statementsenabled, and how old is the current stats window?” - “Which query, and from where — app, BI tool, or ad-hoc?”
- “Can we ship
CREATE INDEX CONCURRENTLY, or is there a maintenance window?”
Self-rubric
- 3NF unless I justified the violation in a comment on the DDL.
- Every FK has an index on both sides.
-
ON DELETEpolicy stated on every FK (CASCADE / RESTRICT / SET NULL). - No bare
VARCHARwithout length orTEXTwithout a reason. - Migration is expand-contract and reversible at each step.
- EXPLAIN ANALYZE captured for every performance recommendation, not just EXPLAIN.
-
CREATE INDEX CONCURRENTLY, never bareCREATE INDEX, in production. - ERD attached so a reviewer can audit the model in one screen.
-
scripts/check_ddl.shexits 0 (schema side);scripts/check_explain.pyexits 0 (tuning side).
Constraints
- MUST: surrogate PK on every table;
created_at/updated_aton every entity; FKs named<table>_id. - MUST: one index migration per file; idempotent (
IF NOT EXISTS). - MUST NOT: introduce M:M without a join table; rely on app code for referential integrity; ship a destructive migration without a verified backfill.
References
- references/postgres-schema-design.md — 3NF/BCNF, surrogate PKs, ON DELETE policies, expand-contract migrations, ERD generation
- references/postgres-performance.md — pg_stat_statements, EXPLAIN (ANALYZE, BUFFERS), index types and strategy, partitioning, bloat, autovacuum
- references/mysql.md — schema design and indexing essentials for MySQL; lighter reference, expandable
- references/elasticsearch.md — mapping, queries, and aggregation basics; lighter reference, expandable
- references/redis.md — data structures, eviction policies, and key patterns; lighter reference, expandable
scripts/check_ddl.sh <schema.sql>— flags any FOREIGN KEY with no explicit ON DELETE policy, and any CREATE TABLE with no PRIMARY KEY (Postgres-specific DDL checker)scripts/check_explain.py <review.md>— flags a performance write-up that recommends a fix with no EXPLAIN evidence or unnamed indexes (Postgres-specific EXPLAIN checker)- PostgreSQL documentation
- Use The Index, Luke! — Postgres-native indexing patterns
- Refactoring Databases — patterns catalog
- STANDARDS.md — stack defaults and routing rules.