Langsung ke konten
Skillpedia
Database18k · #10698

postgres-expert

Fungsinya

Skill ini memandu pekerjaan PostgreSQL, termasuk optimasi kueri, pengindeksan, perancangan skema, transaksi, dan pemantauan. Skill ini untuk pengembang dan administrator basis data yang menjalankan PostgreSQL di produksi.

Kapan dipakai

  • ✓Saat kueri PostgreSQL lambat dan memerlukan analisis atau indeks.
  • ✓Saat Anda merancang skema baru atau memutuskan cara menormalisasi tabel.
  • ✓Saat Anda ingin menemukan kueri lambat atau tabel dengan banyak pemindaian sekuensial.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Kueri ini pada tabel pesanan kami memakan waktu delapan detik. Periksa rencana eksekusinya dan sarankan indeks yang memperbaikinya.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini meminta agent membaca rencana kueri sebelum dan sesudah setiap perubahan, memilih jenis indeks yang tepat, dan menjaga transaksi tetap singkat.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Apa itu EXPLAIN ANALYZE?

Itu menunjukkan cara PostgreSQL benar-benar menjalankan kueri, termasuk waktu dan pemakaian buffer, sehingga Anda bisa melihat di mana waktu habis.

Jenis indeks apa yang sebaiknya dipakai?

Skill ini menyarankan B-tree untuk kesamaan dan rentang, GIN untuk teks penuh dan JSONB, dan BRIN untuk tabel besar yang terurut.

Bagaimana cara menemukan kueri lambat?

Skill ini merekomendasikan ekstensi pg_stat_statements untuk mengidentifikasi kueri yang lambat.

Detail

Deskripsi asli dari pembuat

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

repo: RightNow-AI/openfang

Popularitas

Bintang GitHub
18k
Peringkat
#10698
Lisensi
Apache-2.0
Diperbarui
2/7/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa