postgres-patterns

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

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill postgres-patterns-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/postgres-patterns
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill postgres-patterns-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing efficient and secure PostgreSQL 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. This Skill gives you a quick-reference guide of proven PostgreSQL patterns based on Supabase best practices. ## Core Features & Use Cases - Index Selection Guide: Cheat sheet mapping query patterns to the right index type (B-tree, GIN, BRIN, composite, partial, covering). - Data Type & Schema Guidance: Correct type choices for IDs, strings, timestamps, money, and flags, plus RLS policy and UPSERT patterns. - Anti-Pattern Detection: Ready-to-run SQL queries to find unindexed foreign keys, slow queries via pg_stat_statements, and table bloat. - Use Case: When a query on your orders table is slow, use this Skill to identify the right composite index order (equality columns first, then range columns) and verify the fix with pg_stat_statements. ## Quick Start Ask the agent to review your PostgreSQL query or schema and suggest the right index and data types using the postgres-patterns reference.

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: B-tree for equality and range comparisons, composite indexes for multi-column filters, GIN for jsonb containment and full-text search, and BRIN for time-series ranges. Put equality columns before range columns in composite indexes.

How do I find slow queries in PostgreSQL?▼

Enable the pg_stat_statements extension and query it for statements with high mean_exec_time, for example filtering where mean_exec_time exceeds 100 milliseconds. Sort by mean_exec_time descending to find the worst offenders.

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 instead of float, and boolean for flags. These choices avoid precision, timezone, and storage pitfalls.

How do I write an optimized Row Level Security policy in PostgreSQL?▼

Wrap the auth function call in a SELECT subquery, such as USING ((SELECT auth.uid()) = user_id). This prevents the function from being re-evaluated for every row, significantly improving policy performance on large tables.

Why is OFFSET pagination slow in PostgreSQL and what is the alternative?▼

OFFSET pagination is O(n) because the database must scan and discard all skipped rows. Use cursor (keyset) pagination instead, filtering with WHERE id > last_id and ordering by id, which runs in O(1) with an index.