본문으로 건너뛰기
Skillpedia
데이터베이스18k · #10698

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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 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
자주 묻는 질문

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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬