Agent SkillsRightNow-AI/openfang › postgres-expert

postgres-expert

GitHub

PostgreSQL专家技能,涵盖查询优化、索引策略、模式设计及运维管理。指导高效SQL编写、执行计划分析、分区与锁机制应用,避免常见性能陷阱,提升数据库生产环境稳定性与读写性能。

crates/openfang-skills/bundled/postgres-expert/SKILL.md RightNow-AI/openfang

Trigger Scenarios

需要优化慢查询或分析执行计划 设计或重构数据库表结构与索引 配置PostgreSQL参数或处理高并发连接

Install

npx skills add RightNow-AI/openfang --skill postgres-expert -g -y
More Options

Non-standard path

npx skills add https://github.com/RightNow-AI/openfang/tree/main/crates/openfang-skills/bundled/postgres-expert -g -y

Use without installing

npx skills use RightNow-AI/openfang@postgres-expert

指定 Agent (Claude Code)

npx skills add RightNow-AI/openfang --skill postgres-expert -a claude-code -g -y

安装 repo 全部 skill

npx skills add RightNow-AI/openfang --all -g -y

预览 repo 内 skill

npx skills add RightNow-AI/openfang --list

SKILL.md

Frontmatter
{
    "name": "postgres-expert",
    "description": "PostgreSQL expert for query optimization, indexing, extensions, and database administration"
}

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 WITH for readability but be aware that prior to PostgreSQL 12 they act as optimization barriers; use MATERIALIZED/NOT MATERIALIZED hints 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 RANGE on timestamp columns for time-series data; combine with partition pruning for fast queries
  • Run VACUUM (VERBOSE) and ANALYZE after bulk operations; configure autovacuum_vacuum_scale_factor per-table for heavy-write tables
  • Use pgbouncer in 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; use NOT EXISTS instead
  • Do not set work_mem globally to a large value; it is allocated per-sort-operation and can cause OOM with concurrent queries; set it per-session for analytical workloads

Version History

  • acf2587 Current 2026-08-20 07:39

Same Skill Collection

crates/openfang-hands/bundled/browser/SKILL.md
crates/openfang-hands/bundled/clip/SKILL.md
crates/openfang-hands/bundled/collector/SKILL.md
crates/openfang-hands/bundled/infisical-sync/SKILL.md
crates/openfang-hands/bundled/lead/SKILL.md
crates/openfang-hands/bundled/predictor/SKILL.md
crates/openfang-hands/bundled/researcher/SKILL.md
crates/openfang-hands/bundled/trader/SKILL.md
crates/openfang-hands/bundled/twitter/SKILL.md
crates/openfang-skills/bundled/ansible/SKILL.md
crates/openfang-skills/bundled/api-tester/SKILL.md
crates/openfang-skills/bundled/aws/SKILL.md
crates/openfang-skills/bundled/azure/SKILL.md
crates/openfang-skills/bundled/ci-cd/SKILL.md
crates/openfang-skills/bundled/code-reviewer/SKILL.md
crates/openfang-skills/bundled/compliance/SKILL.md
crates/openfang-skills/bundled/confluence/SKILL.md
crates/openfang-skills/bundled/crypto-expert/SKILL.md
crates/openfang-skills/bundled/css-expert/SKILL.md
crates/openfang-skills/bundled/data-analyst/SKILL.md
crates/openfang-skills/bundled/data-pipeline/SKILL.md
crates/openfang-skills/bundled/docker/SKILL.md
crates/openfang-skills/bundled/elasticsearch/SKILL.md
crates/openfang-skills/bundled/email-writer/SKILL.md
crates/openfang-skills/bundled/figma-expert/SKILL.md
crates/openfang-skills/bundled/gcp/SKILL.md
crates/openfang-skills/bundled/git-expert/SKILL.md
crates/openfang-skills/bundled/github/SKILL.md
crates/openfang-skills/bundled/golang-expert/SKILL.md
crates/openfang-skills/bundled/graphql-expert/SKILL.md
crates/openfang-skills/bundled/helm/SKILL.md
crates/openfang-skills/bundled/interview-prep/SKILL.md
crates/openfang-skills/bundled/jira/SKILL.md
crates/openfang-skills/bundled/kubernetes/SKILL.md
crates/openfang-skills/bundled/linear-tools/SKILL.md
crates/openfang-skills/bundled/linux-networking/SKILL.md
crates/openfang-skills/bundled/llm-finetuning/SKILL.md
crates/openfang-skills/bundled/ml-engineer/SKILL.md
crates/openfang-skills/bundled/mongodb/SKILL.md
crates/openfang-skills/bundled/nextjs-expert/SKILL.md
crates/openfang-skills/bundled/nginx/SKILL.md
crates/openfang-skills/bundled/notion/SKILL.md
crates/openfang-skills/bundled/oauth-expert/SKILL.md
crates/openfang-skills/bundled/openapi-expert/SKILL.md
crates/openfang-skills/bundled/presentation/SKILL.md
crates/openfang-skills/bundled/project-manager/SKILL.md
crates/openfang-skills/bundled/prometheus/SKILL.md
crates/openfang-skills/bundled/prompt-engineer/SKILL.md
crates/openfang-skills/bundled/python-expert/SKILL.md

Metadata

Files
0
Version
acf2587
Hash
b8fe27d2
Indexed
2026-08-20 07:39

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-21 20:29
浙ICP备14020137号-1 $mapa de visitantes$