postgres-performance-tuning
БесплатноБез исполняемых скриптовНе проверенPostgreSQL performance tuning for the docker instance: memory sizing vs the 1g mem_limit (shared_buffers, effective_cache_size, work_mem math), checkpoint…
от fmflurry★ 173 звезды на GitHubОб этом скилле
PostgreSQL Performance Tuning
Target version: postgres:16-alpine — this repository's gc-platform-postgres container: mem_limit: 1g, mem_reservation: 512m, no command: override (stock settings: shared_buffers=128MB, max_connections=100), no shared_preload_libraries.
Contract: diagnostics are read-only (pg_settings, pg_stat_*, EXPLAIN on SELECTs only). Every config change below is emitted ONLY as a ⚠️ HUMAN CONFIRMATION REQUIRED block — if postgres-dba is installed, that agent never applies settings; otherwise database-reviewer or the main agent does not either. Values marked ⚠️ are established heuristics, not guarantees: measure before and after every change, one parameter at a time.
Connection:
docker exec gc-platform-postgres psql -U gcplatform -d gcplatform -c "<query>"
1. Memory sizing vs the 1g mem_limit
Current settings (verify live):
SELECT name, setting, unit FROM pg_settings
WHERE name IN ('shared_buffers','effective_cache_size','work_mem','maintenance_work_mem',
'max_connections','huge_pages');
⚠️ Heuristic sizing for a dedicated 1g container:
| Parameter | Stock | Suggested | Rationale |
|---|---|---|---|
shared_buffers |
128MB | ≈ 256MB | Classic ⚠️ 25%-of-RAM heuristic; the container also needs room for per-backend memory, WAL buffers, and the OS page cache |
effective_cache_size |
4GB (!) | ≈ 512–768MB | Planner hint for "how much caching exists total" (shared_buffers + OS cache). Stock 4GB is a lie on a 1g container and biases the planner toward index scans it shouldn't trust |
work_mem |
4MB | keep 4–8MB | Allocated PER sort/hash node PER connection. Worst case ≈ max_connections × nodes-per-query × work_mem: 100 × 4 nodes × 8MB = 3.2GB ≫ 1g. Raising it globally is how containers OOM; raise per-session for known big sorts instead |
maintenance_work_mem |
64MB | 128–256MB | Used by VACUUM/CREATE INDEX; few concurrent users, safe to raise |
⚠️ HUMAN CONFIRMATION REQUIRED
# docker-compose.yml, postgres service (restart required):
command: ["postgres",
"-c", "shared_buffers=256MB",
"-c", "effective_cache_size=768MB",
"-c", "maintenance_work_mem=128MB"]
Verify after restart: SELECT name, setting FROM pg_settings WHERE name = 'shared_buffers'; and watch docker stats under load.
2. Checkpoint tuning
Source: https://www.postgresql.org/docs/16/wal-configuration.html
Diagnose first (see postgres-health-check §7):
SELECT checkpoints_timed, checkpoints_req,
ROUND(checkpoints_req::numeric / NULLIF(checkpoints_timed + checkpoints_req, 0) * 100, 2) AS req_pct
FROM pg_stat_checkpointer;
SHOW max_wal_size; SHOW checkpoint_completion_target; SHOW checkpoint_warning;
⚠️ Heuristics:
max_wal_size(default 1GB): raise to 2–4GB ifreq_pct> 10–20% — more WAL between checkpoints = fewer forced checkpoints = smoother I/O (cost: longer crash recovery, morepg_waldisk).checkpoint_completion_target = 0.9— already the default since PG14; spreads checkpoint writes across 90% of the interval. Verify it, don't blindly set it.checkpoint_warning = 30s(default): logs when checkpoints are too close together; keep it as the canary.
⚠️ HUMAN CONFIRMATION REQUIRED
command: ["postgres", "-c", "max_wal_size=2GB", "-c", "checkpoint_completion_target=0.9"]
3. Enabling pg_stat_statements
The stock compose loads no extensions (shared_preload_libraries empty), so pg_stat_statements — the single highest-value slow-query tool — is unavailable until enabled.
Source: https://www.postgresql.org/docs/16/pgstatstatements.html ⚠️ (must be loaded via shared_preload_libraries → requires server restart, not a reload; the extension object then still needs CREATE EXTENSION per database).
⚠️ HUMAN CONFIRMATION REQUIRED
# docker-compose.yml, postgres service (restart required):
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements",
"-c", "pg_stat_statements.max=10000",
"-c", "pg_stat_statements.track=all"]
Then the extension itself is a migration (a repo change). If coder is installed, dispatch to that agent. Otherwise the main agent loads the coder skill and writes the migration inline.
⚠️ HUMAN CONFIRMATION REQUIRED
-- Applied as an EF Core migration under the superuser/migrator connection, never ad hoc:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
Combine with §1/§2 if changing both: a single command: array holds all -c flags.
4. Slow-query triage workflow
Requires §3 enabled. Order of operations:
-- 1. Worst by TOTAL time (the queries costing the most aggregate):
SELECT LEFT(query, 100) AS query, calls,
round(total_exec_time::numeric, 1) AS total_ms,
round(mean_exec_time::numeric, 1) AS mean_ms,
rows,
round((shared_blks_hit * 100.0 / NULLIF(shared_blks_hit + sh
Установить postgres-performance-tuning в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл postgres-performance-tuning?
PostgreSQL performance tuning for the docker instance: memory sizing vs the 1g mem_limit (shared_buffers, effective_cache_size, work_mem math), checkpoint tuning (max_wal_size, checkpoint_completion_target, pg_stat_checkpointer), pg_stat_statements enablement via compose, slow-query triage, EXPLAIN (ANALYZE, BUFFERS) interpretation, and pgbouncer transaction-pooling constraints (SET/LISTEN-NOTIFY/PREPARE/advisory locks/WITH HOLD). Use when asked about postgres tuning, slow queries, shared_buffers, work_mem, pg_stat_statements, pgbouncer, or checkpoint tuning. Target: postgres:16-alpine (container gc-platform-postgres). If `postgres-dba` is installed, read this alongside that agent; otherwise read it alongside `database-reviewer` or do the work in the main agent.
Как установить скилл postgres-performance-tuning?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл postgres-performance-tuning запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
ci-review
The scan that the plugin's GitHub Action runs.
от Anthropicazure-static-web-apps
Helps create, configure, and deploy Azure Static Web Apps using the SWA CLI. Use when deploying static sites to Azure, setting up SWA local development…
от GitHubai-ready
Make any repo AI-ready — analyzes your codebase and generates AGENTS.md, copilot-instructions.md, CI workflows, issue templates, and more. Mines your PR…
от GitHubaws-cdk-python-setup
Setup and initialization guide for developing AWS CDK (Cloud Development Kit) applications in Python. This skill enables users to configure environment…
от GitHub