agentleFS
kaynetikkaynetik/skills/ultimate-db/SKILL.md

ultimate-db

Skill1 starsChanged 8 months agoMITView on GitHub

Database engineering guidance covering schema design, indexing, query optimization, replication, and production operations across relational, document, and columnar stores. Primary focus is PostgreSQL; covers MySQL, MongoDB, ClickHouse, Redis, SQLite, and DuckDB. Use when designing schemas, optimizing slow queries, choosing index types, reviewing migrations, setting up replication, modeling documents, handling VACUUM/MVCC, or when the user mentions SQL, NoSQL, OLAP, EXPLAIN, index bloat, sharding, partitioning, or any named database system.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the relevant reference file before making engine-specific decisions.

    line 22
  2. Very specific:

    Measure before changing: Use EXPLAIN ANALYZE (SQL), .explain("executionStats") (MongoDB), or the engine equivalent before adding indexes or …

    line 30
  3. Distinctive:

    Parameterized queries always: No string interpolation into SQL or query builders.

    line 33
  4. Distinctive:

    Follow ESR order for compound indexes (applies to SQL and MongoDB alike):

    line 39

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Ultimate Database Engineering

Engine-agnostic principles first. For engine-specific patterns, indexes, and operational details see the reference/ files.

Reference files

EngineFileWhen to read
PostgreSQLreference/postgresql.mdSQL, MVCC, JSONB, FTS, RLS, replication, pooling, extensions
MySQLreference/mysql.mdInnoDB, charset, fulltext, replication
MongoDBreference/mongodb.mdDocument modeling, aggregation, Atlas
ClickHousereference/clickhouse.mdOLAP, MergeTree engines, insert strategy
Redisreference/redis.mdCaching, pub/sub, streams, data structures
SQLitereference/sqlite.mdEmbedded, WAL, local-first applications
DuckDBreference/duckdb.mdIn-process OLAP, Parquet, analytics

Read the relevant reference file before making engine-specific decisions. Always check docs for the exact version in use.

Universal principles

These apply regardless of engine, paradigm, or scale:

  1. Design for access patterns. Model data around the queries you run, not idealized normal form.
  2. Indexes are the primary performance lever. A missing index on a large table turns milliseconds into seconds.
  3. Measure before changing. Use EXPLAIN ANALYZE (SQL), .explain("executionStats") (MongoDB), or the engine equivalent before adding indexes or rewriting queries.
  4. Smallest correct type. Over-provisioned types waste cache, IO, and index space.
  5. Short transactions. Long-running transactions block vacuuming, lock acquisition, and replication everywhere.
  6. Parameterized queries always. No string interpolation into SQL or query builders.
  7. Mutations are expensive in append-optimized engines. In ClickHouse and similar, model to avoid UPDATE/DELETE; prefer reinsert or versioned rows.
  8. Enforce invariants at the database layer. Constraints, domains, and check constraints catch bugs that application code misses.

Index decision guide

Follow ESR order for compound indexes (applies to SQL and MongoDB alike):

  1. Equality predicates -- most selective first.
  2. Sort columns -- eliminates in-memory sort.
  3. Range predicates -- last.
-- Query: WHERE status = 'active' AND created_at > $1 ORDER BY priority DESC
CREATE INDEX idx_tasks ON tasks (status, priority DESC, created_at);
ScenarioGo-to index type
Equality / range / sort (general)B-tree (all SQL engines)
JSONB containment / array overlapGIN (PostgreSQL)
Full-text searchGIN on tsvector (PG) / FULLTEXT (MySQL) / Atlas Search (Mongo)
GeospatialGiST / PostGIS (PG) -- 2dsphere (Mongo)
Filtered subset of rowsPartial index (WHERE clause)
Avoid heap fetchCovering index (INCLUDE)
Large append-only time-seriesBRIN (PG) / ORDER BY date column (ClickHouse)
Auto-expiryTTL index (Mongo) / partition drop (PG, ClickHouse)

Query anti-patterns (universal)

PatternFix
Function on indexed column in WHEREUse expression index or rewrite the predicate
OFFSET n pagination on large tablesKeyset / cursor pagination
SELECT *Name only the columns needed
LIKE '%term%' on plain columnFull-text index or trigram index
N+1 queriesJOIN, $lookup, or batch IN (...)
Implicit type coercion in predicatesMatch query type to column type exactly
Single-row inserts in batch workloadsBatch 10K+ rows per statement (critical for ClickHouse)

Schema design checklist

  • Timestamps store timezone (TIMESTAMPTZ, DateTime64('UTC'), ISO 8601).
  • Monetary values use exact decimal type (NUMERIC, DECIMAL, Decimal128).
  • Enumerations use a native enum type or a CHECK constraint, not bare strings.
  • Foreign keys declared and indexed.
  • Partitioning chosen for lifecycle (DROP PARTITION), not as index substitute.
  • Zero-downtime migration path planned: additive first, backfill, then constrain.

Replication and HA summary

EngineStreaming / physicalLogicalRecommended HA tool
PostgreSQLWAL streamingPublications / subscriptionsPatroni
MySQLBinary log (row-based)CDC via DebeziumOrchestrator
MongoDBReplica sets (oplog)Change streamsbuilt-in replica set
ClickHouseReplicatedMergeTree--ClickHouse Keeper
RedisAOF + RDB snapshots--Redis Sentinel / Cluster

For configuration details, failover procedures, and monitoring queries see the relevant reference file.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.