/postgresql-skills:postgres-performance-diagnosticsfrom PostgreSQL Diagnostics and Review
Diagnoses PostgreSQL 18/19 performance using wait-event sampling, cumulative statistics, execution plans, and logs. Targets slow queries, high CPU, wait events, I/O, locking, index design, vacuum backlog, WAL, replication, and resource contention.
Ships in PostgreSQL Diagnostics and Review. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
観測期間を指定し、改善対象のSQL・テーブル・待機を影響順に抽出する。候補の発見、原因の確認、変更案、効果検証を分けて報告する。問題がない根拠と判定不能な項目も示す。
対象インスタンス・DB・役割、症状の時間帯、対象API/バッチ、応答時間と処理量の目標を確認する。提供済みの統計・ログ・計画があれば先に使う。不足情報があっても、判断できる範囲の調査を進める。
収集が必要ならcollection.mdを読む。scripts/collect.pyを同じ接続先で2回実行し、scripts/analyze.pyで区間差分を作る。接続はlibpq設定を使い、--instance-idで対象を識別する。実サーバの版・列・拡張を検出し、未取得や権限不足を「負荷0」に置き換えない。
比較が再起動・reset等で拒否されたら、識別情報を改変して比較を通さない。最新snapshotのactivity/locks等は取得時点の証拠として調べ、同じ起動・役割の中で新しい比較用snapshotを採り直す。
2026-10-26の公式19ドキュメントはRC1。19を正式版と決めつけず、実ビルドと検証結果を報告する。
上から順に、時間を使っている場所へ絞り込む。個別の指標から始めない。
scripts/sample_activity.pyで待機をサンプリングする。まずactivity_coverageと欠測の警告を確認し、観測できた平均アクティブセッション数とCPU・I/O・Lock・LWLock等の割合から、読む手順を選ぶ。AASがnullなら観測値は下限として扱う。wait-events.mdanalyze.pyのexec_time_shareとsql_total_exec_msで、区間のtop-level実行時間の大半を占めるSQLを特定する。短いSQLはsql_calls、CPU負荷はsql_shared_blks_accessed、更新負荷はsql_wal_bytesで見る。analyze_plan.pyに通し、hotspotsの自己時間が大きいノードから候補を確認する。currentのxmin_horizon_holders、autovacuum_backlog、freeze_age、redundant_indexes、unused_indexes、invalid_indexes、unindexed_foreign_keysは1時点の規則ベースの候補。定義・設定・統計の観測期間を確認し、autovacuum_unassessedの欠測を併記してから扱う。freeze_ageの比が1以上なら、通常の性能改善より優先して扱う。症状が既に絞られていれば(特定APIだけ遅い、ロック待ちのアラート等)、該当する手順から始めてよい。
アプリのリクエスト単位のtraceがあればscripts/analyze_trace.pyでN+1・過剰取得・pool待ちを判定する。変更の効果は、変更前後の区間レポートをscripts/compare_intervals.pyで比べ、負荷量・キャッシュ条件・結果件数・設定の差を確認してから結論にする。
| 症状・目的 | 手順 | 主な追加入力 |
|---|---|---|
| 全体が遅い、原因の当たりがない、CPU・待機の内訳 | wait-events.md | 症状中の待機サンプル、CPUコア数 |
| 遅いSQL、非効率なスキャン、JOIN/ORDER BY索引、計画退行 | query-tuning.md | SQL・代表パラメータ・DDL・JSON計画・分布 |
| 大量行取得、短いSQLの大量実行、N+1 | query-tuning.md | リクエスト単位のtrace、ORM呼出箇所、転送量 |
| 低ヒット率、I/O待ち、temp落ち、CPU・メモリ・接続競合 | io-memory.md | OS/ストレージ指標、同時実行数、pool待ち |
| ロック待ち、長いトランザクション、deadlock | locking.md | 待機snapshot、DBログ、更新順序 |
| VACUUM遅延、肥大化、freeze、WAL、checkpoint、replication | maintenance-replication.md | 更新量、構成、容量、LSN、保守ログ |
| 変更案の評価と最終レポート | validation.md | 同一条件の前後測定、SLO、変更履歴 |
必要な手順だけを読み、関連する根拠が見つかったときに次の診断へ進む。SQL一覧はsql/queries.jsonにあり、各クエリの依存ビューを示す。
Δtotal_exec_time / Δcallsが区間平均。平均・最大・標準偏差からp95/p99を作らない。$1だけでgeneric planを確定せず、採取時のモードと出所を確認する。pg_stat_statements.rowsは返却/更新行数であり走査行数ではない。付属の収集は読み取りを基本とし、タイムアウトと行数上限を使う。EXPLAIN ANALYZEは対象SQLを実行する。取得済み計画・通常EXPLAINで足りるか検討し、実測が必要なら負荷・副作用を評価して対象と時間を限定する。ROLLBACKでシーケンスや外部への副作用まで必ず戻せるとは扱わない。
原因が設定値(メモリ配分、checkpoint、autovacuum、プランナのコスト等)にあると判断したら、postgres-config-tuningスキルが利用可能ならそれで変更案・適用・検証を具体化する。区間レポートのJSONをその根拠として渡す。
拡張の導入は可能。必要性、提供環境の対応、権限、再起動/負荷、代替手段を確認して、対象環境で許可された範囲で行う。DDL、設定変更、再起動、セッション終了は診断結果とは分けて具体的な変更案にし、既に与えられた実行権限の範囲を守る。
最初に利用者への影響と優先候補を示し、各候補に対象、期間、数値の根拠、仮説と確信度、不足情報、改善案、変更コスト、検証・切り戻しを添える。付属解析の候補をそのまま確定原因にしない。validation.mdの形式を使い、同じ現象の重複提案をまとめる。
代表負荷の設計・再生と、変更の採用判定にはpostgres-workload-validationを使う。
agents/openai.yaml (opens in a new tab)references/collection.md (opens in a new tab)references/io-memory.md (opens in a new tab)references/locking.md (opens in a new tab)references/maintenance-replication.md (opens in a new tab)references/query-tuning.md (opens in a new tab)references/validation.md (opens in a new tab)references/wait-events.md (opens in a new tab)scripts/analyze.py (opens in a new tab)scripts/analyze_logs.py (opens in a new tab)scripts/analyze_plan.py (opens in a new tab)scripts/analyze_trace.py (opens in a new tab)scripts/collect.py (opens in a new tab)scripts/compare_intervals.py (opens in a new tab)scripts/sample_activity.py (opens in a new tab)sql/activity.sql (opens in a new tab)sql/analyze_progress.sql (opens in a new tab)sql/archiver.sql (opens in a new tab)sql/autovacuum_scores.sql (opens in a new tab)sql/bgwriter.sql (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub soudai/postgresql-use-improve-agents-skill --plugin postgresql-skills5 skills in this plugin
/postgres-config-tuningReview and optimize PostgreSQL 18 and 19 server configuration (postgresql.conf, ALTER SYSTEM, role/database settings, managed-service parameter groups). Use when asked to tune, size or audit memory, connections, WAL/checkpoints, autovacuum, planner, I/O, parallelism, JIT, logging or timeouts; produce evidence-backed changes with apply, verify and rollback steps./postgres-schema-reviewReview PostgreSQL table design for missing constraints, naming inconsistencies, mixed lifecycles and responsibilities, mutable facts, nullable or flag semantics, and contention. Use to report refactoring candidates from schema snapshots, domain contracts and observed writes./postgres-security-reviewReview PostgreSQL roles, row level security, authentication, TLS, deployment privileges and security updates. Use to assess exposure, propose scoped remediation, or verify security changes using catalog snapshots, access contracts and staging tests./postgres-workload-validationCompare PostgreSQL SQL, index, or configuration changes under a reproducible workload. Use for benchmark design, pgbench replay, capacity and latency regressions, and accept, investigate, or roll back decisions.Other plugins' skills for the same job