postgres-patterns

Optimize PostgreSQL SQL queries and schema design with index and configuration guidance.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Help developers and DBAs stop performance regressions, misdesigned schemas, and security mistakes by providing targeted PostgreSQL patterns for query optimization, indexing, data typing, and row-level security guidance.

Core Features & Use Cases

  • Index guidance: Recommend B-tree, GIN, BRIN, composite, partial, and covering indexes and when to use each.
  • Schema and type guidance: Advise correct column types for IDs, timestamps, money, and flags to avoid common inefficiencies.
  • Performance troubleshooting: Provide queries and checks to find slow statements, unindexed foreign keys, and table bloat using pg_stat_statements and system catalogs.
  • Concurrency and queue patterns: Offer patterns for safe queue processing, cursor pagination, and upsert semantics.
  • Security and RLS: Suggest secure Row Level Security policies and secure schema defaults and configuration recommendations for connection and timeout limits.

Quick Start

Ask postgres-patterns to review a slow SQL query and recommend the optimal index, schema tweak, and configuration change to improve performance.

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 and find missing indexes?

To optimize slow PostgreSQL queries, use pg_stat_statements to identify bottlenecks and apply targeted B-tree, GIN, or BRIN indexes to accelerate data retrieval and resolve performance regressions.

When should I use BRIN vs GIN indexes in PostgreSQL?

Use BRIN indexes for large tables with naturally sorted data to minimize storage overhead, and use GIN indexes for complex data types like arrays or full-text search to enable fast multi-value lookups.

What is the best way to secure row-level data in PostgreSQL schemas?

The best way to secure row-level data in PostgreSQL is by implementing Row Level Security policies, ensuring users only access rows matching specific criteria while maintaining secure schema defaults.

How do I configure PostgreSQL settings for OLTP and analytical workloads?

Configure PostgreSQL for OLTP and analytical workloads by tuning parameters like max_connections, work_mem, and statement_timeout to balance concurrent transaction throughput and heavy query memory allocations.

Why does PostgreSQL table bloat happen and how can I troubleshoot it?

PostgreSQL table bloat happens due to frequent updates and deletes leaving dead tuples. Troubleshoot it by inspecting VACUUM metrics and system catalogs to identify unindexed foreign keys and reclaim space.

What are the correct PostgreSQL column types for IDs, timestamps, and money?

The correct PostgreSQL column types for IDs, timestamps, and money are UUID or BIGINT for IDs, TIMESTAMPTZ for timestamps, and NUMERIC for money to prevent rounding errors and ensure data integrity.