claude.symlink/skills/database/SKILL.md
Database optimization, query tuning, migrations, and administration. Use for database performance issues, schema design, or operational tasks.
npx skillsauth add htlin222/dotfiles databaseInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Optimize queries, manage schemas, and ensure reliability.
-- PostgreSQL
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM orders WHERE user_id = 123;
-- MySQL
EXPLAIN ANALYZE
SELECT * FROM orders WHERE user_id = 123;
-- Add missing index
CREATE INDEX CONCURRENTLY idx_orders_user_id
ON orders(user_id);
-- Composite index for common queries
CREATE INDEX idx_orders_user_date
ON orders(user_id, created_at DESC);
-- Partial index for filtered queries
CREATE INDEX idx_active_orders
ON orders(user_id) WHERE status = 'active';
-- Cover index to avoid table lookup
CREATE INDEX idx_orders_covering
ON orders(user_id) INCLUDE (total, status);
-- Safe column addition (no lock)
ALTER TABLE users ADD COLUMN preferences JSONB;
-- Safe column rename (use view for compatibility)
ALTER TABLE users RENAME COLUMN name TO full_name;
CREATE VIEW users_compat AS
SELECT *, full_name as name FROM users;
-- Safe index creation
CREATE INDEX CONCURRENTLY idx_new ON table(column);
-- Backfill in batches
UPDATE users SET new_col = compute(old_col)
WHERE id BETWEEN 1 AND 10000;
-- Repeat for next batch
-- Active connections (PostgreSQL)
SELECT state, count(*)
FROM pg_stat_activity
GROUP BY state;
-- Long running queries
SELECT pid, now() - query_start as duration, query
FROM pg_stat_activity
WHERE state = 'active' AND now() - query_start > '5 minutes'::interval;
-- Table sizes
SELECT relname, pg_size_pretty(pg_total_relation_size(relid))
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC
LIMIT 10;
-- Index usage
SELECT indexrelname, idx_scan, idx_tup_read
FROM pg_stat_user_indexes
ORDER BY idx_scan DESC;
-- PostgreSQL vacuum and analyze
VACUUM ANALYZE table_name;
-- Reindex
REINDEX INDEX CONCURRENTLY idx_name;
-- Kill long query
SELECT pg_terminate_backend(pid);
import redis
cache = redis.Redis()
def get_user(user_id: int) -> dict:
# Try cache first
cached = cache.get(f"user:{user_id}")
if cached:
return json.loads(cached)
# Query database
user = db.query("SELECT * FROM users WHERE id = %s", user_id)
# Cache with TTL
cache.setex(f"user:{user_id}", 3600, json.dumps(user))
return user
def invalidate_user(user_id: int):
cache.delete(f"user:{user_id}")
Input: "This query is slow" Action: Run EXPLAIN, identify missing index or bad plan, optimize
Input: "Set up database backups" Action: Configure pg_dump/mysqldump, set schedule, test restore
testing
Converts narrative medical text into Pocket Medicine bullet-style notes with proper abbreviations, then modularizes sections exceeding 20 lines into linked standalone files.
devops
Use when deploying Docker services on the local VM (hostname: vm, Pop!_OS) with Traefik reverse proxy and Homepage dashboard. Covers crane image workflow, Traefik file-provider registration, Homepage services.yaml entries, and compose templates on the traefik-proxy network.
development
Use when reviewing a data visualization or figure for clarity, checking if a graph communicates its message without additional context, or iterating on R/Python plot scripts until a naive reader can fully understand the figure.
development
Runs Vale prose linter on markdown/text files and auto-fixes issues. Use when the user asks to lint, proofread, or improve writing quality of markdown or text files.