database-performance-tuning
Diagnoses and fixes slow Postgres and MySQL/InnoDB databases: measure first, read the plan, change one thing, verify. Use when a query, endpoint, job or…
от fcsouza★ 29 звёзд на GitHub
Установить database-performance-tuning в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Database Performance Tuning
Someone says "it's slow". Turn that into a number, find where the time goes, change the smallest thing that moves the number, and prove it moved. This skill is vendor-neutral: it covers plain Postgres and MySQL. For platform features, see Related skills.
Boundary with other skills
- This skill: why a query is slow and what to change. Measurement, plans, indexes, rewrites, vacuum, bloat, safe rollout.
postgresql-optimization, if installed: Postgres features (JSONB, arrays, ranges, full-text search, window functions). Use it for "how do I express this", not "why is this slow".postgres-game-schema: schema design for game backends.- Managed platforms (Supabase, Neon, PlanetScale): pooling, branching and provider limits are in their own skills, listed under Related skills.
The loop
Measure, get the plan, classify, change one thing, verify. Every index costs write throughput, WAL and vacuum time, so earn each one.
0. Establish the ground truth
Facts here are version-gated. Run this first and keep the major version in view:
SELECT version();
SELECT name, setting FROM pg_settings
WHERE name IN ('shared_buffers','work_mem','effective_cache_size',
'random_page_cost','track_io_timing','max_parallel_workers_per_gather');
SELECT extname, extversion FROM pg_extension;
If pg_stat_statements is missing, say so and ask before installing it. It needs
shared_preload_libraries and a restart.
Version table. It is the one copy; the references link here. Sources are in references/sources.md, checked 2026-11-15 against the PostgreSQL 18 manual (18.7 was current).
| Thing | Rule |
|---|---|
pg_stat_statements.total_exec_time |
PG 13+. PG 12 and older call it total_time. |
shared_blk_read_time, shared_blk_write_time |
PG 17+. PG 16 and older: blk_read_time, blk_write_time. |
stats_since, minmax_stats_since |
PG 17+. |
wal_buffers_full, parallel_workers_to_launch, parallel_workers_launched (statements) |
PG 18+. |
Long IN (...) lists collapse to one pg_stat_statements entry, IN ($1 /*, ... */) |
PG 18+ only. On PG 17 and older each list length is its own entry. |
EXPLAIN (ANALYZE) adds BUFFERS by itself |
PG 18+. On PG 17 and older write EXPLAIN (ANALYZE, BUFFERS). |
EXPLAIN (SERIALIZE, MEMORY) |
PG 17+. |
EXPLAIN (GENERIC_PLAN) |
PG 16+. |
pg_stat_io |
PG 16+. |
| B-tree skip scan (leading column may be unconstrained) | PG 18+. On older majors a composite index needs its leading column. |
autovacuum_vacuum_max_threshold |
PG 18+. |
REPACK, REPACK (CONCURRENTLY), EXPLAIN (ANALYZE, IO), parallel autovacuum, pg_plan_advice |
PG 19, not released as of 2026-11-15 (RC 2 on 2026-11-12). Taken from the draft release notes dated 2026-10-09. Recheck at release. |
If unsure whether a feature exists on the server in front of you, ask the server
(SELECT to_regclass('pg_stat_io')) or read the manual for that major.
1. Find where the time goes
Run the bundled diagnostic. It only runs SELECT and SHOW, and adapts to the server
version:
bash <skill-dir>/scripts/pg-diagnose.sh "postgresql://user@host:5432/db"
<skill-dir> is the base directory shown when this skill loads. Options go before the
connection string: -n 30 for more rows, -q to skip the pg_stat_statements sections.
Connection rules for the script:
- No password in the string. A connection string is a process argument and
psshows it. The script refuses one that has a password. Use~/.pgpass(orPGPASSFILE), or aservice=NAMEentry in~/.pg_service.conf.PGPASSWORDworks but the libpq manual advises against it. - Direct connection only. The script sends its read-only and timeout settings as
startup options. PgBouncer rejects startup parameters it does not track, or drops them if
ignore_startup_parameterslistsoptions; tracked ones such asdefault_transaction_read_onlystill apply. The script checksdefault_transaction_read_only,statement_timeoutandlock_timeoutwithSHOWand stops if any is not applied. Details in references/diagnose-postgres.md. - Read-only is a default, not a lock. Any
SETin the session undoes it. For a hard guarantee connect as a role without write privileges, such as one inpg_monitor.
Rank by total time, not mean. A 5 ms query run two million times an hour costs more than a 3-second report run once. They get different fixes.
2. Get the real plan
EXPLAIN (ANALYZE, BUFFERS, VERBOSE, SETTINGS, FORMAT TEXT) <query>;
ANALYZE executes the statement. Wrap writes in a transaction you roll back. Never run it
on production for a statement whose side effects you have not read.
Read bottom-up. Per node look at estimated against actual rows, buffers and loops.
actual time is per loop; multiply before you call a node cheap. See
[
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/apply-safely.md
- references/diagnose-postgres.md
- references/explain-plans.md
- references/index-design.md
- references/maintenance.md
- references/mysql.md
- references/query-rewrites.md
- references/sources.md
- scripts/pg-diagnose.sh
FAQ
Что делает скилл database-performance-tuning?
Diagnoses and fixes slow Postgres and MySQL/InnoDB databases: measure first, read the plan, change one thing, verify. Use when a query, endpoint, job or report is slow, times out or got slower after a deploy; when the question is about indexes (missing, unused, duplicate, composite order, partial, covering), EXPLAIN plans, seq scans, N+1 queries, slow pagination, bloat, autovacuum, stale statistics, lock pileups, connection limits, or a migration that locked a table; or when a page is slow and the first job is to find out whether the database is the cause. Also for "query lenta", "banco lento", "falta indice", "travou a tabela".
Как установить скилл database-performance-tuning?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл database-performance-tuning запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
docx
AnthropicUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
xlsx
AnthropicUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
pptx
AnthropicUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…