postgres

Diagnose and optimize PostgreSQL schema design, indexing, queries, and operations.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill postgres-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/postgres
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill postgres-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? PostgreSQL performance and reliability issues—slow queries, table bloat, connection exhaustion, unsafe migrations, and XID wraparound—are hard to diagnose without deep operational knowledge. This Skill provides structured guidance for schema design, query optimization, and production operations so you can resolve database problems systematically instead of guessing. ## Core Features & Use Cases - Query Performance Diagnosis: Use EXPLAIN (ANALYZE, BUFFERS) workflows, pg_stat_statements, and sargable predicate rewrites to find and fix slow queries. - Schema and Index Design: Apply correct data types (timestamptz, bigserial, text), composite/partial/covering indexes, and partitioning strategies for large tables. - Safe Migrations: Add NOT NULL columns and create indexes concurrently without locking production tables. - Operations & Troubleshooting: Configure PgBouncer pooling, tune autovacuum, monitor WAL/checkpoints, plan backups and PITR, and manage replication. - Use Case: Your orders table queries suddenly take 10 seconds. Use this Skill to run EXPLAIN ANALYZE, identify a sequential scan, and create a covering index that restores sub-millisecond reads. ## Quick Start Ask the agent to analyze a slow PostgreSQL query using EXPLAIN ANALYZE and recommend an index to fix it.

Frequently Asked Questions about postgres

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

FAQPage Schema
How do I find and fix slow queries in PostgreSQL?

Run EXPLAIN (ANALYZE, BUFFERS) on the slow query and look for sequential scans on large tables, sorts without indexes, or nested loops on unindexed joins. Add an appropriate index, then re-run to confirm the plan changed. Use pg_stat_statements to find the worst queries by total_exec_time.

How do I add a column or index without locking a PostgreSQL table?

Use CREATE INDEX CONCURRENTLY to build indexes without blocking writes. For NOT NULL columns, add the column as nullable, backfill in batches, then set the default and NOT NULL constraint—Postgres 11+ makes constant defaults instant without a table rewrite.

Should I use PgBouncer with PostgreSQL?

Yes for OLTP workloads, because Postgres forks a process per connection and direct connections are expensive. Use transaction pooling mode for web traffic, but note that prepared statements, LISTEN/NOTIFY, temp tables, and session-level SET commands do not survive transaction-mode pooling.

Why is my PostgreSQL table bloated and how do I fix it?

Bloat comes from dead tuples that VACUUM has not reclaimed, often caused by long-running transactions or lagging autovacuum. Check n_dead_tup in pg_stat_user_tables, kill idle-in-transaction sessions, and tune autovacuum per-table. Avoid VACUUM FULL in production since it takes an exclusive lock.

When should I partition a PostgreSQL table?

Consider partitioning when tables exceed roughly 100GB or 20M rows, or around 50GB for time-series and log data with retention needs. Partitioning mainly benefits maintenance and data retention via dropping old partitions rather than raw query speed, so do not apply it prematurely.

What is XID wraparound in PostgreSQL and how do I prevent it?

XID wraparound occurs when 32-bit transaction IDs exhaust ~2 billion values, forcing the database into emergency shutdown to prevent data appearing invisible. Prevent it by never disabling autovacuum, keeping transactions short, and alerting when age(datfrozenxid) exceeds 40-50% of the wraparound limit.