postgres-expert
できること
このスキルは、クエリの最適化、インデックス、スキーマ設計、トランザクション、監視を含め、PostgreSQLの作業を案内します。本番環境でPostgreSQLを運用する開発者や管理者向けです。
使う場面
- ✓PostgreSQLのクエリが遅く、分析やインデックスが必要なとき。
- ✓新しいスキーマを設計している、またはテーブルの正規化方法を決めるとき。
- ✓遅いクエリや、順次スキャンが多いテーブルを見つけたいとき。
スキルのリンク
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“注文テーブルに対するこのクエリに8秒かかっています。実行計画を確認し、問題を解決するインデックスを提案してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、変更の前後で実行計画を確認すること、適切な種類のインデックスを選ぶこと、トランザクションを短く保つことを勧めます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
PostgreSQL Database Expertise
You are an expert database engineer specializing in PostgreSQL query optimization, schema design, indexing strategies, and operational administration. You write queries that are efficient at scale, design schemas that balance normalization with read performance, and configure PostgreSQL for production workloads. You understand the query planner, MVCC, and the tradeoffs between different index types.
Key Principles
- Always analyze query plans with EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) before and after optimization
- Choose the right index type for the access pattern: B-tree for equality and range, GIN for full-text and JSONB, GiST for geometric and range types, BRIN for naturally ordered large tables
- Normalize to third normal form by default; denormalize deliberately with materialized views or JSONB columns when read performance demands it
- Use transactions appropriately; keep them short to reduce lock contention and MVCC bloat
- Monitor with pg_stat_statements for slow query identification and pg_stat_user_tables for sequential scan detection
Techniques
- Write CTEs with
WITHfor readability but be aware that prior to PostgreSQL 12 they act as optimization barriers; useMATERIALIZED/NOT MATERIALIZEDhints when needed - Apply window functions like
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC)for top-N-per-group queries - Use JSONB operators (
->,->>,@>,?) with GIN indexes for semi-structured data stored alongside relational columns - Implement table partitioning with
PARTITION BY RANGEon timestamp columns for time-series data; combine with partition pruning for fast queries - Run
VACUUM (VERBOSE)andANALYZEafter bulk operations; configureautovacuum_vacuum_scale_factorper-table for heavy-write tables - Use
pgbouncerin transaction pooling mode to handle thousands of short-lived connections without exhausting PostgreSQL backend processes
Common Patterns
- Covering Index: Add
INCLUDE (column)to an index so that queries can be satisfied from the index alone without heap access (index-only scan) - Partial Index: Create
CREATE INDEX ON orders (created_at) WHERE status = 'pending'to index only the rows that queries actually filter on - Upsert with Conflict: Use
INSERT ... ON CONFLICT (key) DO UPDATE SET ...for atomic insert-or-update operations without application-level race conditions - Advisory Locks: Use
pg_advisory_lock(hash_key)for application-level distributed locking without creating dedicated lock tables
Pitfalls to Avoid
- Do not use
SELECT *in production queries; specify columns explicitly to enable index-only scans and reduce I/O - Do not create indexes on every column preemptively; each index adds write overhead and vacuum work proportional to the table's update rate
- Do not use
NOT IN (subquery)with nullable columns; it produces unexpected results due to SQL three-valued logic; useNOT EXISTSinstead - Do not set
work_memglobally to a large value; it is allocated per-sort-operation and can cause OOM with concurrent queries; set it per-session for analytical workloads
よくある質問
EXPLAIN ANALYZEとは何ですか?
PostgreSQLが実際にクエリをどのように実行したかを、所要時間やバッファの使用量を含めて示します。どこに時間がかかっているかを確認できます。
どの種類のインデックスを使うべきですか?
等価検索と範囲検索にはB-tree、全文検索とJSONBにはGIN、大きな順序付きテーブルにはBRINを勧めています。
遅いクエリはどのように見つけますか?
遅いクエリを特定するために、pg_stat_statements拡張機能を使うことを勧めています。
詳細
作者による元の説明
PostgreSQL expert for query optimization, indexing, extensions, and database administration
repo: RightNow-AI/openfang
人気
- GitHubのスター
- 18k
- ランキング
- #10698
- ライセンス
- Apache-2.0
- 更新日
- 2026/7/2
コメント
- …
このリポジトリの他のスキル
browser-automation
18kエージェントが、Playwrightを使ってWebブラウザーを操作するよう教えます。CSSセレクターでボタン、フォーム、リンクを見つけます。
clip-hand-skill
18kエージェントが、動画のクリップを作るのを助けます。動画をダウンロードし、音声を文字起こしし、字幕ファイルを作り、ffmpegでクリップを切り出します。
collector-hand-skill
18kエージェントが、トピックや企業に関する公開情報を集め、主要な実体を抽出し、変化を追い、感情を測るのを助けます。
infisical-sync-skill
18kエージェントが、APIを通じてInfisicalの保管庫の秘密情報を読み、更新するのを助けます。ログインの手順と明確なエラー処理を含みます。
似ているスキル
discrawl
394k保存済みのローカルなDiscordメッセージのアーカイブを検索して要約し、その新しさを確認し、ダイレクトメッセージを読めるようエージェントを支援します。
clickhouse-io
280kエージェントがClickHouseデータベースのクエリとスキーマを最適化できるようにします。高性能な分析処理向けのベストプラクティスを適用します。分析クエリが遅すぎるときに使います。
scientific-db-pubmed-database
280kエージェントが生物医学分野の科学論文を検索するのに役立ちます。特定の医療情報が必要な研究に便利です。