agentleFS
troskatertroskater/flowdeck-claude/skills/postgres-patterns/SKILL.md

postgres-patterns

Skill0 starsChanged 22 days agoMITView on GitHub

PostgreSQL schema, query, indexing, and performance patterns.

46 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use content-hash-cache-pattern, configure-ecc and 10 more.

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.
  • royaluniondesign-sysSkill

    content-hash-cache-pattern

    Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

    Also in 17 projects that use this

  • royaluniondesign-sysSkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 12 projects that use this

  • junimnjwSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 12 projects that use this

  • loulanyueSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 10 projects that use this

  • ronmkrSkill

    vite-patterns

    Vite build tool patterns including config, plugins, HMR, env variables, proxy setup, SSR, library mode, dependency pre-bundling, and build optimization. Activate when working with vite.config.ts, Vite plugins, or Vite-based projects.

    Also in 8 projects that use this

  • RojiosSkill

    dart-flutter-patterns

    Production-ready Dart and Flutter patterns covering null safety, immutable state, async composition, widget architecture, popular state management frameworks (BLoC, Riverpod, Provider), GoRouter navigation, Dio networking, Freezed code generation, and clean architecture.

    Also in 7 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When designing database schemas, writing complex queries, or optimizing database performance.

    line 10
  2. Distinctive:

    Design indexes strategically: - Create individual btree indexes on each column for multi-column searches (allows BitmapAnd)

    line 13
  3. Distinctive:

    Use EXPLAIN ANALYZE: - Always verify query plans before and after optimization

    line 14
  4. Distinctive:

    Run ANALYZE regularly: - Keep statistics fresh for optimal planner decisions

    line 18

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

postgres-patterns

When to Activate

When designing database schemas, writing complex queries, or optimizing database performance. Use before creating migrations or writing SQL queries.

Steps

  1. Design indexes strategically - Create individual btree indexes on each column for multi-column searches (allows BitmapAnd)
  2. Use EXPLAIN ANALYZE - Always verify query plans before and after optimization
  3. Choose correct index type - B-tree for equality/range, Bloom for multi-column filters with high selectivity
  4. Avoid multi-column btree on non-leading columns - Queries on non-first columns of multi-column btree indexes will do sequential scans
  5. Use parameterized queries - Let the planner cache and reuse query plans
  6. Run ANALYZE regularly - Keep statistics fresh for optimal planner decisions

Examples

-- AVOID: Multi-column btree for non-leading column queries
CREATE INDEX btreeidx ON tbloom (i1, i2, i3, i4, i5, i6);
-- Query on i2 and i5 will do sequential scan, not use the index

-- PREFER: Individual btree indexes for multi-column searches
CREATE INDEX btreeidx1 ON tbloom (i1);
CREATE INDEX btreeidx2 ON tbloom (i2);
CREATE INDEX btreeidx3 ON tbloom (i3);
CREATE INDEX btreeidx4 ON tbloom (i4);
CREATE INDEX btreeidx5 ON tbloom (i5);
CREATE INDEX btreeidx6 ON tbloom (i6);
-- Bitmap Index Scan with BitmapAnd is used for multi-column queries
-- Bloom Index for multi-column filtering (good for low selectivity columns)
CREATE INDEX bloomidx ON tbloom USING bloom (i1, i2, i3, i4, i5, i6);
-- More efficient than btree for queries filtering on many columns
-- Smaller index size, faster Bitmap Index Scans

-- Always verify with EXPLAIN ANALYZE
EXPLAIN ANALYZE SELECT * FROM tbloom WHERE i2 = 898732 AND i5 = 123451;
-- Query Planner Configuration (temporary fix only)
SET enable_hashjoin = off;           -- Force nested-loop or merge join
SET enable_seqscan = off;           -- Prefer index scans
SET random_page_cost = 1.1;         -- Make index scans cheaper (SSD)
SET effective_cache_size = '8GB';   -- Help planner estimate

-- Better approaches:
-- 1. Run ANALYZE to update statistics
ANALYZE;
-- 2. Increase statistics for specific columns
ALTER TABLE orders SET STATISTICS = 500;
ANALYZE orders;
-- 3. Adjust planner cost constants (postgresql.conf)
-- Repository Pattern in SQL
-- Define standard operations
interface OrderRepository {
  findAll(filter: OrderFilter, pagination: Pagination): Promise<Order[]>;
  findById(id: string): Promise<Order | null>;
  create(order: CreateOrderDTO): Promise<Order>;
  update(id: string, attributes: UpdateOrderDTO): Promise<Order>;
  delete(id: string): Promise<void>;
  count(filter?: OrderFilter): Promise<number>;
}

Related Skills

  • api-design
  • backend-patterns
  • database-migrations
  • postgres-performance

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.