postgres-best-practices

Optimizes Postgres queries, schemas, and configurations using Supabase performance rules.

1|Updated Jul 20, 2026
One-click install
npx skills add https://github.com/gonzoblasco/ai-developer-stack --skill postgres-best-practices-gonzoblasco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: postgres-best-practices
Source: https://github.com/gonzoblasco/ai-developer-stack/tree/main/backend-infra/postgres-best-practices
Command: npx skills add https://github.com/gonzoblasco/ai-developer-stack --skill postgres-best-practices-gonzoblasco

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Slow queries, missing indexes, connection exhaustion, and insecure Row-Level Security policies are the most common causes of Postgres performance degradation, and they are hard to diagnose without deep database expertise. ## Core Features & Use Cases - Prioritized Rule Library: Provides performance rules across 8 categories (query performance, connection management, security & RLS, schema design, locking, data access, monitoring, advanced features), each with incorrect vs. correct SQL examples and quantified impact. - Schema Auditing: Includes a Python script that scans SQL schema files for anti-patterns such as serial primary keys, varchar(n) columns, unindexed foreign keys, and mixed-case identifiers. - Health Diagnostics: Ships a SQL script that reports cache hit ratios, unused indexes, tables needing VACUUM, and long-running queries. - Use Case: When reviewing a migration file before deployment, run the audit script to catch unindexed foreign keys and wrong data types, then apply the referenced rules to rewrite the schema with identity columns, timestamptz, and proper indexes. ## Quick Start Ask the AI to review your Postgres schema or slow query using the postgres-best-practices rules and suggest optimized SQL.

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 Postgres queries?▼

Start by adding indexes on WHERE and JOIN columns, which can yield 100-1000x speedups on large tables. Use EXPLAIN ANALYZE to confirm sequential scans, then apply composite, covering, or partial indexes depending on your query filters.

How to audit a Postgres schema for best practices?▼

Run the included audit_schema.py script against your SQL file to detect serial primary keys, varchar(n) columns, unindexed foreign keys, and mixed-case identifiers. Each finding references the recommended fix such as identity columns or timestamptz.

Does connection pooling work with prepared statements in Postgres?▼

Named prepared statements fail in transaction-mode pooling because connections are shared between requests. Use unnamed prepared statements, deallocate after use, or switch to session-mode pooling where connections persist.

Why is my Row Level Security policy slow in Postgres?▼

RLS policies that call functions like auth.uid() per row cause severe slowdowns on large tables. Wrap function calls in a SELECT subquery so they execute once, and add indexes on columns referenced in policies.

When should I partition a Postgres table?▼

Partition tables exceeding roughly 100 million rows, time-series data queried by date ranges, or tables where you need to drop old data efficiently. Range partitioning by timestamp enables instant partition drops instead of slow DELETE operations.