postgres-patterns

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

5|Updated Feb 6, 2026
One-click install
npx skills add https://github.com/FaisalAlqarni/sp-ecc --skill postgres-patterns-faisalalqarni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/FaisalAlqarni/sp-ecc/tree/main/skills/postgres-patterns
Command: npx skills add https://github.com/FaisalAlqarni/sp-ecc --skill postgres-patterns-faisalalqarni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides quick guidance and best practices for PostgreSQL database operations, helping to optimize query performance, design robust schemas, and enhance security.

Core Features & Use Cases

  • Query Optimization: Learn efficient indexing strategies (B-tree, GIN, BRIN) and composite/covering/partial index usage.
  • Schema Design: Understand recommended data types for common use cases (IDs, strings, timestamps, money, flags).
  • Security & Patterns: Implement Row Level Security (RLS) policies, UPSERT operations, cursor pagination, and queue processing patterns.
  • Anti-Pattern Detection: Identify common pitfalls like unindexed foreign keys, slow queries, and table bloat.

Quick Start

Use the postgres-patterns skill to find an example of an optimized RLS policy.

Frequently Asked Questions about postgres-patterns

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

FAQPage Schema
How do I optimize PostgreSQL query performance using the right index types?

To optimize PostgreSQL query performance, you should use specific index types like B-tree, GIN, or BRIN based on your data access patterns, and apply composite, covering, or partial indexes to speed up slow queries.

What are common PostgreSQL schema design anti-patterns causing table bloat?

Common PostgreSQL schema design anti-patterns causing table bloat and slow queries include using unindexed foreign keys and inefficient data types, which can be detected and resolved using established database patterns.

How do I implement Row Level Security (RLS) policies in PostgreSQL?

You can implement Row Level Security (RLS) policies in PostgreSQL by applying specific security best practices and policy patterns to restrict data access at the row level directly within the database schema.

What is the best way to handle UPSERT and cursor pagination in PostgreSQL?

The best way to handle UPSERT and cursor pagination in PostgreSQL is to use standard SQL patterns designed for these operations, ensuring efficient data updates and stable large dataset retrieval.

What data types should I use for IDs, timestamps, and money in PostgreSQL schema design?

For PostgreSQL schema design, you should use recommended data types specifically suited for IDs, strings, timestamps, money, and flags to ensure robust structures and optimal query performance.