agentleFS
kumaran-iskumaran-is/claude-code-onboarding/.claude/skills/postgres-best-practices/SKILL.md

postgres-best-practices

Skill35 starsChanged 6 months agoMITView on GitHub

Supabase PostgreSQL best practices library — 33 impact-rated rules (CRITICAL→LOW) covering connection pooling, RLS, locking, VACUUM, full-text search, and JSONB indexing. Use when writing, reviewing, or optimizing PostgreSQL queries, schema, or configuration.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use ponytail.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • GoogleSkill

    ponytail

    Forces the laziest solution that actually works, simplest, shortest, most minimal. Channels a senior dev who has seen everything: question whether the task needs to exist at all (YAGNI), reach for the standard library before custom code, native platform features before dependencies, one line before fifty. Supports intensity levels: lite, full (default), ultra. Use on ANY coding task: writing, adding, refactoring, fixing, reviewing, or designing code, and choosing libraries or dependencies. Also use whenever the user says "ponytail", "be lazy", "lazy mode", "simplest solution", "minimal solution", "yagni", "do less", or "shortest path", or complains about over-engineering, bloat, boilerplate, or unnecessary dependencies. Do NOT use for non-coding requests (general knowledge, prose, translation, summaries, recipes).

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NEVER TUNE WHAT YOU HAVEN'T MEASURED — CHECK pg_stat_statements AND pg_stat_activity BEFORE CHANGING CONFIGURATION OR ADDING INDEXES

    line 18

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Iron Law

NEVER TUNE WHAT YOU HAVEN'T MEASURED — CHECK pg_stat_statements AND pg_stat_activity BEFORE CHANGING CONFIGURATION OR ADDING INDEXES

When to Use This Skill

  • Configuring connection pooling (PgBouncer, Prisma pool, asyncpg pool, R2DBC pool)
  • Implementing Row Level Security (RLS) for multi-tenant data isolation
  • Designing worker queues with SKIP LOCKED and advisory locks
  • Preventing deadlocks in concurrent write workloads
  • Configuring VACUUM/ANALYZE and autovacuum tuning
  • Adding full-text search with tsvector/tsquery
  • Indexing JSONB columns (jsonb_ops vs jsonb_path_ops)
  • Reviewing any PostgreSQL schema or query against the 8-category rule library

Do Not Use This Skill When

  • You need query EXPLAIN analysis and index pattern SQL (use sql-optimization-patterns)
  • You need schema migration design or ERDs (use database-schema-designer)
  • You need cloud analytics or HTAP (use sql-pro)

Rule Categories by Priority

PriorityCategoryImpactRules
1Query PerformanceCRITICALrules/query-*.md (5 rules)
2Connection ManagementCRITICALrules/conn-*.md (4 rules)
3Security & RLSCRITICALrules/security-*.md (3 rules)
4Schema DesignHIGHrules/schema-*.md (6 rules)
5Concurrency & LockingMEDIUM-HIGHrules/lock-*.md (4 rules)
6Data Access PatternsMEDIUMrules/data-*.md (4 rules)
7Monitoring & DiagnosticsLOW-MEDIUMrules/monitor-*.md (3 rules)
8Advanced FeaturesLOWrules/advanced-*.md (2 rules)

Quick Rule Index

Connection Management (NEW — not in other skills)

  • rules/conn-pooling.md — PgBouncer setup, pool size formula (cores × 2) + spindles, transaction vs session mode
  • rules/conn-limits.md — max_connections calculation, prevent database OOM crash
  • rules/conn-idle-timeout.md — Reclaim 30-50% idle connection slots
  • rules/conn-prepared-statements.md — Prepared statement conflicts in transaction-mode pooling

Concurrency & Locking (NEW — not in other skills)

  • rules/lock-skip-locked.md — Atomic claim-and-update queue pattern, 10x worker throughput
  • rules/lock-deadlock-prevention.md — Consistent lock ordering, deadlock prevention patterns
  • rules/lock-short-transactions.md — Minimize transaction duration, 3-5x throughput
  • rules/lock-advisory.md — Application-level coordination without row-level locks

Security & RLS (NEW depth — not in other skills)

  • rules/security-rls-basics.md — ALTER TABLE ... ENABLE ROW LEVEL SECURITY + policy patterns
  • rules/security-rls-performance.md — SECURITY DEFINER functions, 5-10x faster RLS queries
  • rules/security-privileges.md — Principle of least privilege, specific GRANT patterns

Monitoring & Maintenance (NEW — not in other skills)

  • rules/monitor-vacuum-analyze.md — VACUUM/ANALYZE patterns, autovacuum tuning
  • rules/monitor-pg-stat-statements.md — Enable and query pg_stat_statements
  • rules/monitor-explain-analyze.md — EXPLAIN ANALYZE usage guide

Advanced Features (NEW — not in other skills)

  • rules/advanced-full-text-search.md — tsvector, ts_rank, GIN full-text index, 100x vs LIKE
  • rules/advanced-jsonb-indexing.md — GIN index, jsonb_ops vs jsonb_path_ops trade-off

Query Performance (complementary to sql-optimization-patterns)

  • rules/query-missing-indexes.md — EXPLAIN Seq Scan detection
  • rules/query-index-types.md — B-tree/GIN/BRIN/Hash selection
  • rules/query-composite-indexes.md — Leftmost prefix rule
  • rules/query-covering-indexes.md — INCLUDE columns for Index Only Scan
  • rules/query-partial-indexes.md — Filtered index subsets

Schema Design (complementary to database-schema-designer)

  • rules/schema-primary-keys.md — IDENTITY vs UUID vs UUIDv7
  • rules/schema-data-types.md — Forbidden types, correct alternatives
  • rules/schema-foreign-key-indexes.md — Diagnostic SQL to find all missing FK indexes
  • rules/schema-lowercase-identifiers.md — snake_case, no quoted identifiers
  • rules/schema-partitioning.md — Range partitioning patterns
  • rules/schema-foreign-key-indexes.md — FK index enforcement

Stack Integration

Python / FastAPI (asyncpg + SQLAlchemy)

  • Connection pooling: asyncpg pool min_size/max_size configuration (see rules/conn-pooling.md)
  • RLS: set app.current_user_id session variable before queries
  • SKIP LOCKED: use in background task workers

NestJS / Prisma

  • Connection pooling: DATABASE_URL=...?connection_limit=10&pool_timeout=20 (see rules/conn-pooling.md)
  • Prepared statements: Prisma uses prepared statements — use session mode or pgbouncer=true parameter
  • SKIP LOCKED: use prisma.$queryRaw for queue worker queries

Java / Spring Boot WebFlux (R2DBC)

  • Connection pooling: r2dbc.pool.max-size, r2dbc.pool.initial-size (see rules/conn-pooling.md)
  • RLS: use ConnectionFactory with per-request session variable injection

Related Skills

  • database-schema-designer — Schema design, Flyway migrations, normalization
  • sql-optimization-patterns — EXPLAIN analysis, N+1, cursor pagination, batch ops
  • postgresql — PostgreSQL-specific types, gotchas, extensions, JSONB depth
  • sql-pro — Cloud analytics, HTAP, BigQuery/Snowflake
  • vector-database — pgvector HNSW/IVFFlat alignment

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.