postgres-patterns

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides quick guidance on best practices for PostgreSQL, helping developers optimize queries, design efficient schemas, and implement robust indexing and security.

Core Features & Use Cases

  • Index Optimization: Understand when to use B-tree, GIN, or BRIN indexes.
  • Schema Design: Choose appropriate data types and learn common patterns like composite and partial indexes.
  • Security & Performance: Implement Row Level Security policies and optimize common operations like UPSERT and pagination.
  • Use Case: Quickly reference the correct index type for a WHERE jsonb @> '{}' clause or find the optimal order for columns in a composite index.

Quick Start

Use the postgres-patterns skill to find the correct index type for time-series data ranges.

Frequently Asked Questions about postgres-patterns

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

FAQPage Schema
What is the best way to optimize PostgreSQL queries for jsonb filtering?

To optimize PostgreSQL queries filtering jsonb data, use a GIN index. This index type efficiently handles containment operators like `@>`, significantly accelerating complex JSON document searches.

How do I choose the right PostgreSQL index type for time-series data?

For time-series data ranges in PostgreSQL, BRIN indexes are highly effective. They provide block range indexing, consuming minimal space while delivering fast results for naturally ordered time-series datasets.

When do I need to implement Row Level Security in PostgreSQL?

Implement Row Level Security (RLS) in PostgreSQL when you must restrict data access at the database level. RLS policies ensure users only view or modify rows they are explicitly permitted to access.

What is the optimal column order for a composite index in PostgreSQL?

The optimal column order for a PostgreSQL composite index places the columns with the highest selectivity or equality constraints first, followed by range constraints, maximizing index utilization during queries.

Why does my PostgreSQL query slow down on unindexed foreign keys?

PostgreSQL queries slow down on unindexed foreign keys because joins and cascade deletes require full table scans. Adding an index to foreign key columns resolves this anti-pattern and restores performance.

How do I perform a PostgreSQL UPSERT or cursor pagination correctly?

Perform a PostgreSQL UPSERT using the ON CONFLICT clause, and implement cursor pagination by utilizing keyset pagination techniques. These SQL patterns ensure efficient data modifications and traversal.