postgres-patterns

Optimize PostgreSQL schemas, queries, indexes, and Row Level Security policies.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the common pain points of slow PostgreSQL query performance, poorly optimized database schemas, missing indexes, and misconfigured security settings that lead to operational bottlenecks, data bloat, and vulnerability to unauthorized access.

Core Features & Use Cases

  • Query Optimization: Use the right index types (B-tree, GIN, BRIN) and patterns (covering, partial, composite) to speed up common query workloads, and identify slow queries and unindexed foreign keys.
  • Schema Design: Select optimal data types, design efficient table structures, and implement cursor pagination and queue processing patterns to avoid performance degradation as data scales.
  • Security & Maintenance: Configure Row Level Security policies, set appropriate connection limits and timeouts, and detect table bloat to maintain secure, high-performing production databases.
  • Use Case: A backend developer building a multi-tenant SaaS application can use this Skill to design an optimized orders table schema with proper composite indexes and RLS policies to ensure fast, secure access for all tenants.

Quick Start

Use the postgres-patterns skill to review your existing e-commerce orders table schema and generate a list of recommended composite indexes and Row Level Security policies for your customer and admin roles.

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 query performance in a production database?

Optimize slow PostgreSQL queries by applying proven indexing patterns like B-tree, GIN, and BRIN alongside covering, partial, and composite indexes. This identifies unindexed foreign keys and accelerates common query workloads to remove operational bottlenecks.

What's the best way to design a PostgreSQL schema for a multi-tenant SaaS application?

Design multi-tenant SaaS schemas by selecting optimal data types, structuring efficient tables, and implementing cursor pagination. This prevents performance degradation as data scales while supporting fast and secure tenant access.

How do I configure Row Level Security policies in PostgreSQL for customer and admin roles?

Configure Row Level Security policies to enforce strict data access boundaries for customer and admin roles. This secures multi-tenant data against unauthorized access and meets production-grade compliance requirements.

When should I use BRIN versus GIN indexes for PostgreSQL database optimization?

Use BRIN indexes for large tables with naturally ordered data and GIN indexes for composite data types. Matching the index type to your specific query workload accelerates data retrieval and minimizes storage overhead.

How do I detect and resolve table bloat during PostgreSQL database maintenance?

Detect and resolve table bloat by running maintenance queries that identify storage inefficiencies. Configuring appropriate connection limits and timeouts maintains high-performing production databases and prevents operational bottlenecks.