postgres-patterns

Provide PostgreSQL schema design, query optimization, indexing, and security best practices.

1|Updated Feb 7, 2026
One-click install
npx skills add https://github.com/ndhananj/codex-agent-setup --skill postgres-patterns-ndhananj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-patterns
Source: https://github.com/ndhananj/codex-agent-setup/tree/main/docs/zh-CN/skills/postgres-patterns
Command: npx skills add https://github.com/ndhananj/codex-agent-setup --skill postgres-patterns-ndhananj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides best practices and quick reference guides for designing efficient, secure, and performant PostgreSQL database schemas and queries.

Core Features & Use Cases

  • Schema Design: Guidance on choosing appropriate data types and indexing strategies.
  • Query Optimization: Tips for writing efficient SQL, including indexing and pagination.
  • Security: Best practices for Row-Level Security (RLS) and general security configurations.
  • Use Case: When designing a new table, consult this Skill for recommended data types and indexing strategies to ensure optimal performance from the start.

Quick Start

Use the postgres-patterns skill to generate a CREATE INDEX statement for a WHERE clause filtering on a JSONB column.

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 queries with composite and covering indexes?

Optimize PostgreSQL queries by applying composite indexes for multi-column filters and covering indexes to include data needed by the query, preventing slow performance and table bloat. This skill provides specific best practices for these indexing strategies.

What is the best way to implement cursor pagination in PostgreSQL?

Cursor pagination in PostgreSQL is best implemented using keyset pagination patterns that avoid OFFSET, ensuring stable and efficient traversal of large datasets. This skill outlines the specific SQL patterns required for this approach.

How do I configure Row-Level Security policies in PostgreSQL?

Configure Row-Level Security (RLS) policies in PostgreSQL by applying the security defaults and policy templates provided to restrict row access. This skill includes configuration guidance for enforcing these security boundaries.

Why are my PostgreSQL foreign key queries running slow?

PostgreSQL foreign key queries run slow when foreign keys are unindexed, creating an anti-pattern that degrades join and cascade performance. This skill detects unindexed foreign keys and provides the necessary CREATE INDEX statements.

Can I use partial indexes for conditional queries in PostgreSQL?

Partial indexes in PostgreSQL are used for conditional queries by indexing only rows matching a WHERE clause, reducing index size and improving query speed. This skill provides patterns for generating partial index statements.

When do I need a UPSERT operation in PostgreSQL?

A UPSERT operation in PostgreSQL is needed to insert rows or update existing ones without conflicts, commonly used for queue processing and data synchronization. This skill covers the specific patterns for executing these operations.