agentleFS
jahongashtamcjahongashtamc/hallwright/.agents/skills/postgres-best-practices/SKILL.md

postgres-best-practices

Skill1 starsChanged 13 days agoMITView on GitHub

Production PostgreSQL engineering for high-concurrency applications. Enforces optimal B-tree and GIN indexing, sub-10ms query execution plans, connection pooling (PgBouncer/Supavisor), and deadlock-free transaction isolation.

We split this skill into the rules it gives an agent

7 rules. 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

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

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

    B-tree Indexes: Always index foreign keys (REFERENCES) to avoid full table scans during cascading deletes and JOIN operations.

    line 14
  2. Distinctive:

    EXPLAIN (ANALYZE, BUFFERS): Verify query plans before shipping.

    line 16
  3. Very specific:

    Partial Indexes: Use WHERE active = true or WHERE status = 'pending' for skewed distributions to keep index size minimal and cache-resident.

    line 17
  4. Distinctive:

    Lock Escalation Defense: Avoid long-running transactions.

    line 20
  5. Very specific:

    Safe Migrations: Add columns with default values as DEFAULT ...

    line 21
  6. Very specific:

    Deadlock Prevention: Always acquire locks on rows in deterministic primary-key order (SELECT ...

    line 22
  7. Distinctive:

    Use connection poolers (PgBouncer in transaction mode or Supavisor) to support thousands of concurrent client connections without memory …

    line 25

“Common” is measured: kept by at least 6 in 10 of the 8 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

PostgreSQL Production Best Practices (Supabase & Neon Standards)

Engineering guidelines for robust, high-performance PostgreSQL databases.

1. Indexing & Query Execution Plans

  • B-tree Indexes: Always index foreign keys (REFERENCES) to avoid full table scans during cascading deletes and JOIN operations.
  • Composite Indexes: Order composite index columns by equality filters first, then range/sorting operators (WHERE tenant_id = ? AND created_at > ? -> INDEX (tenant_id, created_at)).
  • EXPLAIN (ANALYZE, BUFFERS): Verify query plans before shipping. Eliminate sequential scans on tables with >1,000 rows.
  • Partial Indexes: Use WHERE active = true or WHERE status = 'pending' for skewed distributions to keep index size minimal and cache-resident.

2. Concurrency & Transaction Isolation

  • Lock Escalation Defense: Avoid long-running transactions. Never hold database locks while performing external network requests (HTTP, email, Stripe calls).
  • Safe Migrations: Add columns with default values as DEFAULT ... (instant in Postgres 11+). Create indexes concurrently with CREATE INDEX CONCURRENTLY to avoid table lockouts.
  • Deadlock Prevention: Always acquire locks on rows in deterministic primary-key order (SELECT ... FOR UPDATE ORDER BY id).

3. Connection Pooling & Resource Scaling

  • Use connection poolers (PgBouncer in transaction mode or Supavisor) to support thousands of concurrent client connections without memory exhaustion.
  • Enforce strict query timeouts: statement_timeout = '5s' to prevent rogue runaway queries from starving connection pools.

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.

Reviews can't be read right now.

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.