Saltar al contenido
Skillpedia
Bases de datos18 mil · #10698

postgres-expert

Qué hace

Esta skill guía el trabajo con PostgreSQL, incluidos la optimización de consultas, la indexación, el diseño de esquemas, las transacciones y la monitorización. Está pensada para desarrolladores y administradores de bases de datos que ejecutan PostgreSQL en producción.

Cuándo usarla

  • ✓Cuando una consulta de PostgreSQL es lenta y necesita análisis o un índice.
  • ✓Cuando diseñas un esquema nuevo o decides cómo normalizar tablas.
  • ✓Cuando quieres encontrar consultas lentas o tablas con muchos escaneos secuenciales.

Link de la skill

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

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/postgres-expert/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Esta consulta sobre nuestra tabla de pedidos tarda ocho segundos. Revisa su plan y sugiere un índice que la arregle.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La skill indica a tu agente que lea el plan de consulta antes y después de cualquier cambio, elija el tipo de índice adecuado y mantenga las transacciones cortas.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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
Preguntas frecuentes

¿Qué es EXPLAIN ANALYZE?

Muestra cómo ejecuta PostgreSQL realmente una consulta, incluidos los tiempos y el uso de búferes, para ver dónde se va el tiempo.

¿Qué tipo de índice debo usar?

La skill sugiere B-tree para igualdad y rangos, GIN para texto completo y JSONB, y BRIN para tablas grandes ordenadas.

¿Cómo encuentro consultas lentas?

La skill recomienda la extensión pg_stat_statements para identificar las consultas lentas.

Detalles

Descripción original del autor

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

repo: RightNow-AI/openfang

Popularidad

Estrellas en GitHub
18 mil
Posición en el ranking
#10698
Licencia
Apache-2.0
Actualizada
2/7/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas