| name | database-ops |
| description | Use when performing database administration, migrations, or performance tuning. Covers PostgreSQL, MySQL, Redis, and MongoDB operations including replication setup, backup/restore, index optimization, connection pooling, and maintenance windows. |
| user-invocable | false |
| allowed-tools | ["Read","Write","Bash","Grep"] |
Database Operations
PostgreSQL Performance Tuning
SELECT query, calls, mean_exec_time, total_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 20;
SELECT relname, seq_scan, idx_scan, seq_tup_read
FROM pg_stat_user_tables
WHERE seq_scan > 0 AND idx_scan = 0
ORDER BY seq_tup_read DESC;
REINDEX INDEX CONCURRENTLY idx_name;
VACUUM (VERBOSE, ANALYZE) table_name;
Zero-Downtime Migration Pattern
ALTER TABLE users ADD COLUMN email_verified boolean;
UPDATE users SET email_verified = false WHERE email_verified IS NULL AND id BETWEEN 1 AND 10000;
ALTER TABLE users ALTER COLUMN email_verified SET DEFAULT false;
ALTER TABLE users ALTER COLUMN email_verified SET NOT NULL;
CREATE INDEX CONCURRENTLY idx_users_email_verified ON users(email_verified);
Redis Best Practices
SET user:{user_id}:profile "{json}"
SET session:{session_id} "{json}" EX 3600
SET cache:products:page:{n} "{json}" EX 300
CONFIG SET maxmemory 256mb
CONFIG SET maxmemory-policy allkeys-lru
Best Practices
- Connection pooling — PgBouncer for PostgreSQL, ProxySQL for MySQL
- Monitoring — Track connections, query time, cache hit ratio, replication lag
- Backups — Automated daily with Point-in-Time Recovery capability
- Indexes — Create concurrently, drop unused, rebuild periodically
- Vacuum — Tune autovacuum, don't disable it
- Upgrades — Test on staging with production-size data