postgres-patterns

Optimizes PostgreSQL schema design and indexing with RLS-aware patterns for maintainable code.

1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill postgres-patterns-khetansarvesh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/khetansarvesh/ai_skills_repo/tree/main/skills/postgres-patterns
Command: npx skills add https://github.com/khetansarvesh/ai_skills_repo --skill postgres-patterns-khetansarvesh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PostgreSQL performance and reliability often suffer from suboptimal schema design, missing or incorrect indexes, and insecure configuration practices.

Core Features & Use Cases

  • Indexing and query optimization: Provides practical index cheat sheets (B-tree, composite, GIN for jsonb/tsvector, BRIN for time ranges) and guidance for choosing the right index for common query shapes.
  • Schema and type best practices: Recommends correct data types (e.g., bigint for IDs, text for strings, timestamptz for timestamps, numeric for money) to avoid avoidable performance and correctness issues.
  • Security and correctness patterns: Includes Row Level Security (RLS) policy patterns, safe UPSERT usage, and robust connection/timeout/monitoring configuration templates aligned with Supabase-style best practices.

Quick Start

Use the postgres-patterns skill when you are designing a new table or fixing slow SQL by asking it to recommend an index strategy and RLS policy for your specific schema and queries.

Frequently Asked Questions about postgres-patterns

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

FAQPage Schema
How do I optimize slow PostgreSQL queries with the right indexes?

To optimize PostgreSQL queries, apply correct index selection using B-tree, composite, GIN for jsonb, and BRIN for time ranges based on your specific query shapes. This approach targets slow lookups and improves overall schema performance.

How do I set up Row Level Security policies in Supabase?

Setting up Row Level Security in Supabase involves applying RLS policy patterns that enforce authorization directly in the database. This ensures safer defaults by restricting data access based on user roles and context.

What are the best data types for PostgreSQL schema design?

The best PostgreSQL data types for schema correctness include bigint for IDs, text for strings, timestamptz for timestamps, and numeric for money. Using these recommended types prevents avoidable performance and correctness issues.

How do I process queues safely in PostgreSQL without locking conflicts?

To process queues safely in PostgreSQL, use the FOR UPDATE SKIP LOCKED SQL construct. This robust pattern allows concurrent queue workers to grab available rows without blocking each other, ensuring reliable background processing.

Does this approach work for cursor-based pagination in PostgreSQL?

Yes, this approach works for cursor pagination in PostgreSQL by applying best-practice SQL constructs. It ensures correct and efficient data retrieval for large datasets, avoiding the performance pitfalls of traditional offset pagination.