postgres-best-practices

Guide PostgreSQL schema, indexing, and migration changes with EXPLAIN verification.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill postgres-best-practices-quanngynx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres-best-practices
Source: https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI/tree/main/servexa-warranty-ai/.cursor/skills/postgres-best-practices
Command: npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill postgres-best-practices-quanngynx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It prevents risky PostgreSQL schema, indexing, and migration changes that can cause performance regressions, locking incidents, or data integrity issues.

Core Features & Use Cases

  • Schema design guidance for choosing correct PostgreSQL data types, defaults, constraints, and nullability.
  • Indexing strategy to support real query patterns while avoiding over-indexing, including partial and text search indexes.
  • Migrations and operational safety covering lock-aware DDL, phased backfills, and rollout sequencing for zero-downtime approaches.

Quick Start

Use this skill when you are about to change tables, add indexes, write or tune a SQL query, or plan a migration, and ask it to recommend the safest approach based on the applicable reference.

Frequently Asked Questions about postgres-best-practices

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

FAQPage Schema
How do I add an index in PostgreSQL without locking the table?

To add an index in PostgreSQL without locking the table, use the CONCURRENTLY keyword during migration. This allows concurrent inserts, updates, and deletes while the index builds, ensuring zero-downtime schema changes.

What is the best way to design PostgreSQL schema constraints for data integrity?

The best way to design PostgreSQL schema constraints for data integrity is to explicitly define NOT NULL, UNIQUE, and FOREIGN KEY constraints. This enforces data validity at the database level and prevents anomalous records.

How do I tune slow PostgreSQL queries using EXPLAIN?

Tune slow PostgreSQL queries by running EXPLAIN (ANALYZE, BUFFERS) to inspect execution plans. This reveals sequential scans, high cost operations, and buffer usage, guiding indexing strategy and query rewrites.

When do I need partial indexes in PostgreSQL?

You need partial indexes in PostgreSQL when queries frequently filter on a specific subset of rows. By indexing only rows matching a WHERE clause, you reduce index size and improve query performance for targeted patterns.

How to plan zero-downtime migrations for large PostgreSQL tables?

Plan zero-downtime migrations for large PostgreSQL tables by using phased backfills and staged rollouts. This approach separates schema changes from data updates, avoiding long-held locks and maintaining application availability.

Why does my PostgreSQL migration cause a performance regression?

PostgreSQL migrations cause performance regressions when adding indexes without CONCURRENTLY or altering columns with heavy locks. Lock-aware DDL operations and verifying execution plans prevent these blocking incidents.