postgres

Provides PostgreSQL best practices for schema design, indexing, query optimization, and operations.

5|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/nuggocto/dotfiles --skill postgres-nuggocto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres
Source: https://github.com/nuggocto/dotfiles/tree/main/opencode/skills/postgres
Command: npx skills add https://github.com/nuggocto/dotfiles --skill postgres-nuggocto

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Working with PostgreSQL involves many pitfalls: slow queries, bloated tables, connection exhaustion, XID wraparound, and misconfigured backups. This Skill gives an AI assistant structured, expert-level PostgreSQL guidance so it can diagnose performance issues, design sound schemas, and advise on operations without guesswork. ## Core Features & Use Cases - Schema and Index Guidance: Covers primary key selection, data types, foreign keys, composite/partial/covering indexes, and audits for unused, duplicate, invalid, or bloated indexes. - Query Optimization: Identifies SQL anti-patterns such as N+1 queries, OFFSET pagination, and non-SARGable filters, with rewritten alternatives. - Operations and Internals: Explains MVCC, VACUUM/autovacuum tuning, WAL and checkpoints, replication, backup/PITR, memory management, partitioning, and monitoring via pg_stat views. - PlanetScale-Specific Workflows: Includes PgBouncer pooling configuration, pscale CLI commands, query insights, and supported extensions for PlanetScale-hosted Postgres. - Use Case: When a user reports a slow dashboard query, the assistant can check pg_stat_statements, detect a missing index from a high rows_read/rows_returned ratio, and propose a composite index with EXPLAIN ANALYZE verification. ## Quick Start Ask the assistant to review your slow PostgreSQL query and suggest indexes or rewrites based on Postgres best practices.

Frequently Asked Questions about postgres

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

FAQPage Schema
How do I find and remove unused indexes in PostgreSQL?

Query pg_stat_user_indexes joined with pg_index for indexes with idx_scan = 0, excluding unique and constraint-backing indexes. Verify stats age first, and always confirm with a human before dropping any index since some serve infrequent but critical workloads.

How do I fix slow PostgreSQL queries?

Start with pg_stat_statements to find queries with high mean_exec_time, then run EXPLAIN ANALYZE. Common fixes include adding composite or partial indexes, rewriting correlated subqueries as JOINs, replacing OFFSET pagination with cursor pagination, and avoiding functions on indexed columns.

When should I use PgBouncer instead of direct PostgreSQL connections?

Use PgBouncer (port 6432 on PlanetScale) for OLTP application traffic with many concurrent connections. Reserve direct connections (port 5432) for DDL, migrations, analytics, temp tables, and session-dependent features, since transaction pooling does not support them.

Why does my PostgreSQL database keep growing despite VACUUM?

VACUUM marks dead tuple space as reusable but does not shrink files or compact index pages. Long-running or idle-in-transaction sessions also block cleanup. Use REINDEX CONCURRENTLY or pg_repack for bloat, and set idle_in_transaction_session_timeout to prevent blocking.

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

PostgreSQL uses 32-bit transaction IDs that wrap around at roughly 2 billion, making old rows invisible. Autovacuum freezes old XIDs to prevent this, so never disable it. Monitor age(datfrozenxid) per database and alert around 40-50% of the wraparound limit.

When should I partition a PostgreSQL table?

Partition general tables exceeding about 100GB or 20M rows, and time-series or log tables beyond 50GB or 10M rows. Partitioning mainly improves maintenance and data retention; the partition key must be part of the primary key, and pg_partman can automate partition management.