Zum Inhalt springen
Skillpedia
Datenbanken18k · #10698

postgres-expert

Was er macht

Dieser Skill führt durch die Arbeit mit PostgreSQL, einschließlich Abfrageoptimierung, Indizierung, Schema-Entwurf, Transaktionen und Überwachung. Er ist für Entwickler und Datenbankadministratoren gedacht, die PostgreSQL im Betrieb nutzen.

Wann du ihn nutzt

  • ✓Wenn eine PostgreSQL-Abfrage langsam ist und analysiert oder indiziert werden muss.
  • ✓Wenn du ein neues Schema entwirfst oder entscheidest, wie Tabellen normalisiert werden.
  • ✓Wenn du langsame Abfragen oder Tabellen mit vielen sequenziellen Scans finden willst.

Link zum Skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Diese Abfrage auf unserer Bestelltabelle braucht acht Sekunden. Prüf ihren Plan und schlag einen Index vor, der das behebt.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Skill weist deinen Agenten an, den Abfrageplan vor und nach jeder Änderung zu lesen, den passenden Indextyp zu wählen und Transaktionen kurz zu halten.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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
Häufige Fragen

Was ist EXPLAIN ANALYZE?

Es zeigt, wie PostgreSQL eine Abfrage tatsächlich ausführt, mit Zeiten und Pufferverbrauch, damit du siehst, wo die Zeit verloren geht.

Welchen Indextyp soll ich nutzen?

Der Skill schlägt B-Tree für Gleichheit und Bereiche vor, GIN für Volltext und JSONB und BRIN für große, sortierte Tabellen.

Wie finde ich langsame Abfragen?

Der Skill empfiehlt die Erweiterung pg_stat_statements, um langsame Abfragen zu identifizieren.

Details

Originalbeschreibung des Autors

PostgreSQL expert for query optimization, indexing, extensions, and database administration

repo: RightNow-AI/openfang

Beliebtheit

GitHub-Sterne
18k
Platz im Ranking
#10698
Lizenz
Apache-2.0
Aktualisiert
2.7.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills