postgres-patterns

Provides PostgreSQL patterns for query optimization, schema design, indexing, and row-level security.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill postgres-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/postgres-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill postgres-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing efficient PostgreSQL queries and schemas requires knowing which index types, data types, and query patterns to use, and mistakes like missing indexes or wrong types cause slow queries and production issues. ## Core Features & Use Cases - Index Selection Guide: Cheat sheet mapping query patterns to the correct index type (B-tree, GIN, BRIN, composite, partial, covering). - Data Type & Schema Best Practices: Reference tables for choosing correct types like bigint IDs, timestamptz, and numeric for money. - Anti-Pattern Detection: Ready-to-run SQL queries that find unindexed foreign keys, slow queries via pg_stat_statements, and table bloat. - Use Case: When writing a migration for a new orders table, consult the patterns to create a composite index on (status, created_at), use timestamptz columns, and add an optimized RLS policy with the SELECT-wrapped auth.uid() pattern. ## Quick Start Ask the AI to review your PostgreSQL schema or slow query using the postgres-patterns skill and suggest proper indexes and data types.

Frequently Asked Questions about postgres-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose the right PostgreSQL index type for my query?

Match the query pattern to the index type: use B-tree for equality and range comparisons, GIN for jsonb containment and full-text search, and BRIN for time-series ranges. For multi-column filters, create a composite index with equality columns first, then range columns.

What data types should I use in PostgreSQL schema design?

Use bigint for IDs, text instead of varchar(255) for strings, timestamptz instead of timestamp for time values, numeric(10,2) for money, and boolean for flags. Avoid float for currency and int for IDs that may grow large.

How do I find slow queries in PostgreSQL?

Enable the pg_stat_statements extension, then query it for statements with mean_exec_time above a threshold such as 100ms, ordered by mean execution time. This identifies which queries need indexing or rewriting.

Why is my PostgreSQL row level security policy slow?

RLS policies that call auth.uid() directly re-evaluate the function per row. Wrap the call in a SELECT subquery, like (SELECT auth.uid()) = user_id, so PostgreSQL caches the result and evaluates it once per query.

How do I detect unindexed foreign keys in PostgreSQL?

Query pg_constraint joined with pg_attribute for foreign key constraints, then check pg_index for a matching index on those columns. Foreign keys without indexes cause slow joins and locking issues during deletes on the referenced table.