postgres-best-practices

Diagnose slow PostgreSQL queries and propose index and query rewrites.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/snuffomega/pricechart --skill postgres-best-practices-snuffomega
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-best-practices
Source: https://github.com/snuffomega/pricechart/tree/main/.skills/postgres-best-practices
Command: npx skills add https://github.com/snuffomega/pricechart --skill postgres-best-practices-snuffomega

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Postgres performance problems caused by missing or incorrect indexes, inefficient query patterns, stale statistics, and unsafe connection/transaction practices.

Core Features & Use Cases

  • Query performance fixes: Identify missing indexes, choose the right index type (B-tree/GiN/BRIN/hash), and design composite/covering/partial indexes to match real query filters and joins.
  • Reliability for high concurrency: Apply connection management guidance (pooling, idle timeouts, connection limits) and safer transaction practices (short transactions, deadlock prevention, SKIP LOCKED patterns for workers).
  • Security and correctness: Improve security posture and Row Level Security (RLS) by using least privilege and structuring RLS policies for performance (e.g., avoiding per-row function calls).

Quick Start

Use the postgres-best-practices skill to review a slow SQL query and propose an index and query rewrite that matches its WHERE/JOIN patterns.

Frequently Asked Questions about postgres-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow PostgreSQL queries with the right indexes?

Optimize slow PostgreSQL queries by matching index types to query filters and joins, choosing B-tree, GiN, BRIN, or composite indexes to align with WHERE and JOIN patterns for faster execution.

What's the best way to manage Postgres connection pooling in Supabase-style environments?

Manage Postgres connection pooling by applying connection limits, idle timeouts, and safely pooled database access practices to maintain reliability under high concurrency workloads.

Why does my PostgreSQL Row Level Security policy cause performance issues?

PostgreSQL Row Level Security policies cause performance issues when using per-row function calls, so structuring RLS policies with least privilege avoids overhead and improves query speed.

How do I prevent deadlocks and manage transactions in PostgreSQL?

Prevent deadlocks and manage PostgreSQL transactions by keeping them short, applying deadlock prevention strategies, and using SKIP LOCKED patterns for worker queues to maintain concurrency.

When do I need to run VACUUM and ANALYZE for Postgres maintenance?

Run VACUUM and ANALYZE for Postgres maintenance when stale statistics degrade performance, ensuring the query planner has accurate data distribution information for optimal execution plans.

Does this approach provide incorrect-vs-correct SQL patterns for query optimization?

Yes, this approach provides actionable guidance using prioritized performance categories with concrete incorrect-vs-correct SQL patterns and clear usage boundaries for query optimization.