postgres-advanced-patterns

Implements PostgreSQL indexing, query optimization, partitioning, and transaction patterns for database design.

Updated May 16, 2026
One-click install
npx skills add https://github.com/organvm-i-theoria/_agent-ontology --skill postgres-advanced-patterns-organvm-i-theoria
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: postgres-advanced-patterns
Source: https://github.com/organvm-i-theoria/_agent-ontology/tree/main/.agents/skills/postgres-advanced-patterns
Command: npx skills add https://github.com/organvm-i-theoria/_agent-ontology --skill postgres-advanced-patterns-organvm-i-theoria

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing performant PostgreSQL queries and designing scalable database schemas requires deep knowledge of indexing strategies, window functions, CTEs, and concurrency control that many developers lack, leading to slow queries and poorly structured databases. ## Core Features & Use Cases - Query Optimization: Provides patterns for effective indexing (B-tree, GIN, GiST, partial, composite), EXPLAIN ANALYZE usage, and EXISTS vs IN strategies. - Advanced SQL Patterns: Covers window functions, recursive CTEs, JSON/JSONB operations, upserts with ON CONFLICT, lateral joins, and full-text search. - Database Design & Concurrency: Includes table partitioning, materialized views, constraints, transaction isolation levels, and row-level locking with SKIP LOCKED. - Use Case: When building an orders dashboard with slow queries, apply composite indexes, rewrite aggregations with conditional FILTER clauses, and add a materialized view for user statistics. ## Quick Start Ask the AI to optimize a slow PostgreSQL query or design a partitioned table schema using these patterns.

Frequently Asked Questions about postgres-advanced-patterns

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

FAQPage Schema
How do I optimize slow PostgreSQL queries?▼

Start with EXPLAIN ANALYZE to inspect the query plan, then add appropriate indexes such as B-tree for equality, partial indexes for filtered queries, or composite indexes for multi-column lookups. Avoid SELECT * and prefer EXISTS over IN for large subqueries.

How to use window functions in PostgreSQL?▼

Window functions like ROW_NUMBER, RANK, SUM OVER, and LAG/LEAD compute values across row sets without grouping. Use PARTITION BY to rank within categories and frame clauses like ROWS BETWEEN 6 PRECEDING AND CURRENT ROW for moving averages.

When should I use GIN vs GiST indexes in PostgreSQL?▼

Use GIN indexes for JSONB containment queries and full-text search on tsvector columns. Use GiST for geometric data, range exclusion constraints, and tsvector search when index size matters more than build speed.

Does PostgreSQL support table partitioning for large datasets?▼

Yes, PostgreSQL supports declarative range, list, and hash partitioning. Create a parent table with PARTITION BY RANGE on a column like created_at, then attach child partitions for specific value ranges to improve query pruning and maintenance.

How do I handle concurrent queue processing in PostgreSQL?▼

Use SELECT ... FOR UPDATE SKIP LOCKED to let multiple workers claim rows without blocking each other. Combine with appropriate transaction isolation levels like SERIALIZABLE for critical operations or REPEATABLE READ for consistent snapshots.

What are the limitations of materialized views in PostgreSQL?▼

Materialized views store stale snapshot data and require manual or scheduled REFRESH to update. REFRESH MATERIALIZED VIEW CONCURRENTLY avoids locking reads but requires a unique index on the view.