Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
affaan-m avatar

Postgres Patterns

  • 7.8k installs
  • 238k repo stars
  • Updated August 5, 2026
  • affaan-m/everything-claude-code

postgres-patterns is an agent skill that provides PostgreSQL index, schema, RLS, pagination, and anti-pattern patterns for query optimization based on Supabase practices.

About

The postgres-patterns skill is a PostgreSQL quick reference for query optimization, schema design, indexing, and security based on Supabase best practices. Agents match index types to query patterns including B-tree equality and range filters, composite indexes, GIN for JSONB and full text, and BRIN for time series. Data type guidance favors bigint IDs, text strings, timestamptz, numeric money, and boolean flags over weaker alternatives. Patterns cover composite index column order, covering indexes with INCLUDE, partial indexes, optimized RLS policies wrapping auth.uid in SELECT, UPSERT, cursor pagination, and queue processing with FOR UPDATE SKIP LOCKED. Anti-pattern SQL finds unindexed foreign keys, slow pg_stat_statements queries, and table bloat. A configuration template sets connection limits, work_mem, timeouts, pg_stat_statements, and public schema revokes. Activation triggers include writing SQL, designing schemas, troubleshooting slow queries, implementing RLS, and connection pooling. Related tools include database-reviewer, backend-patterns, and database-migrations skills.

  • Index cheat sheet mapping query patterns to B-tree, GIN, composite, and BRIN indexes.
  • Data type quick reference for IDs, strings, timestamps, money, and boolean flags.
  • RLS, UPSERT, cursor pagination, and SKIP LOCKED queue processing examples.
  • Anti-pattern queries for unindexed foreign keys, slow statements, and bloat.
  • Configuration template for connections, work_mem, timeouts, and pg_stat_statements.

Postgres Patterns by the numbers

  • 7,805 all-time installs (skills.sh)
  • +246 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #19 of 911 Databases skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

postgres-patterns capabilities & compatibility

Capabilities
index type selection for equality, range, jsonb, · schema data type recommendations · rls, upsert, and cursor pagination sql patterns · queue processing with for update skip locked · anti pattern detection for fk indexes and bloat
Works with
postgres · supabase
Use cases
database · api development · debugging
From the docs

What postgres-patterns says it does

PostgreSQL database patterns for query optimization, schema design, indexing, and security.
SKILL.md
Equality columns first, then range columns
SKILL.md
npx skills add https://github.com/affaan-m/everything-claude-code --skill postgres-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs7.8k
repo stars238k
Security audit3 / 3 scanners passed
Last updatedAugust 5, 2026
Repositoryaffaan-m/everything-claude-code

What PostgreSQL index, data type, and query patterns should I use to avoid slow queries and schema anti-patterns?

Apply PostgreSQL index, schema, RLS, pagination, and anti-pattern patterns for query optimization and safe configuration.

Who is it for?

Developers writing PostgreSQL SQL, migrations, or RLS who want a concise pattern reference during implementation.

Skip if: Skip for non-PostgreSQL databases or full automated schema reviews (use database-reviewer agent instead).

When should I use this skill?

User writes SQL queries, designs schemas, troubleshoots slow PostgreSQL queries, implements RLS, or sets up connection pooling.

What you get

Concrete SQL patterns for indexes, RLS, UPSERT, cursor pagination, queue locking, and diagnostic queries plus a baseline config template.

  • Index recommendations
  • RLS policy patterns
  • Schema and pooling guidance

By the numbers

  • Index cheat sheet documents multiple index types including B-tree, BRIN, and GIN with query-pattern mappings
  • Originates from the Everything Claude Code (ECC) collection with Supabase-aligned PostgreSQL guidance

Files

SKILL.mdMarkdownGitHub ↗

PostgreSQL Patterns

Quick reference for PostgreSQL best practices. For detailed guidance, use the database-reviewer agent.

When to Activate

  • Writing SQL queries or migrations
  • Designing database schemas
  • Troubleshooting slow queries
  • Implementing Row Level Security
  • Setting up connection pooling

Quick Reference

Index Cheat Sheet

Query PatternIndex TypeExample
WHERE col = valueB-tree (default)CREATE INDEX idx ON t (col)
WHERE col > valueB-treeCREATE INDEX idx ON t (col)
WHERE a = x AND b > yCompositeCREATE INDEX idx ON t (a, b)
WHERE jsonb @> '{}'GINCREATE INDEX idx ON t USING gin (col)
WHERE tsv @@ queryGINCREATE INDEX idx ON t USING gin (col)
Time-series rangesBRINCREATE INDEX idx ON t USING brin (col)

Data Type Quick Reference

Use CaseCorrect TypeAvoid
IDsbigintint, random UUID
Stringstextvarchar(255)
Timestampstimestamptztimestamp
Moneynumeric(10,2)float
Flagsbooleanvarchar, int

Common Patterns

Composite Index Order:

-- Equality columns first, then range columns
CREATE INDEX idx ON orders (status, created_at);
-- Works for: WHERE status = 'pending' AND created_at > '2024-01-01'

Covering Index:

CREATE INDEX idx ON users (email) INCLUDE (name, created_at);
-- Avoids table lookup for SELECT email, name, created_at

Partial Index:

CREATE INDEX idx ON users (email) WHERE deleted_at IS NULL;
-- Smaller index, only includes active users

RLS Policy (Optimized):

CREATE POLICY policy ON orders
  USING ((SELECT auth.uid()) = user_id);  -- Wrap in SELECT!

UPSERT:

INSERT INTO settings (user_id, key, value)
VALUES (123, 'theme', 'dark')
ON CONFLICT (user_id, key)
DO UPDATE SET value = EXCLUDED.value;

Cursor Pagination:

SELECT * FROM products WHERE id > $last_id ORDER BY id LIMIT 20;
-- O(1) vs OFFSET which is O(n)

Queue Processing:

UPDATE jobs SET status = 'processing'
WHERE id = (
  SELECT id FROM jobs WHERE status = 'pending'
  ORDER BY created_at LIMIT 1
  FOR UPDATE SKIP LOCKED
) RETURNING *;

Anti-Pattern Detection

-- Find unindexed foreign keys
SELECT conrelid::regclass, a.attname
FROM pg_constraint c
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = ANY(c.conkey)
WHERE c.contype = 'f'
  AND NOT EXISTS (
    SELECT 1 FROM pg_index i
    WHERE i.indrelid = c.conrelid AND a.attnum = ANY(i.indkey)
  );

-- Find slow queries
SELECT query, mean_exec_time, calls
FROM pg_stat_statements
WHERE mean_exec_time > 100
ORDER BY mean_exec_time DESC;

-- Check table bloat
SELECT relname, n_dead_tup, last_vacuum
FROM pg_stat_user_tables
WHERE n_dead_tup > 1000
ORDER BY n_dead_tup DESC;

Configuration Template

-- Connection limits (adjust for RAM)
ALTER SYSTEM SET max_connections = 100;
ALTER SYSTEM SET work_mem = '8MB';

-- Timeouts
ALTER SYSTEM SET idle_in_transaction_session_timeout = '30s';
ALTER SYSTEM SET statement_timeout = '30s';

-- Monitoring
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

-- Security defaults
REVOKE ALL ON SCHEMA public FROM public;

SELECT pg_reload_conf();

Related

  • Agent: database-reviewer - Full database review workflow
  • Skill: backend-patterns - API and backend patterns
  • Skill: database-migrations - Safe schema changes

When to Use This Skill

  • Writing SQL queries
  • Designing database schemas
  • Optimizing query performance
  • Implementing Row Level Security
  • Troubleshooting database issues
  • Setting up PostgreSQL configuration

---

Based on Supabase Agent Skills (credit: Supabase team) (MIT License)

Related skills

Forks & variants (1)

Postgres Patterns has 1 known copy in the catalog totaling 1.5k installs. They canonicalize to this original listing.

How it compares

Pick postgres-patterns for quick Supabase-aligned index and RLS reference during SQL authoring; escalate to database-reviewer for full schema audits.

FAQ

Which index type fits JSONB containment queries?

GIN indexes, for example CREATE INDEX idx ON t USING gin (col) for jsonb @> filters.

What is the recommended ID column type?

bigint rather than int or random UUID for primary identifiers per the data type reference.

How should RLS policies reference auth.uid?

Wrap auth.uid() in a SELECT subquery inside the policy USING clause for optimized evaluation.

Is Postgres Patterns safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Databasesdatabases

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.