postgres

Diagnose and optimize PostgreSQL performance, schema design, replication, and operations.

Updated Aug 25, 2026
One-click install
npx skills add https://github.com/AliJ021/labelmod-core --skill postgres-alij021
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgres
Source: https://github.com/AliJ021/labelmod-core/tree/main/.claude/skills/postgres
Command: npx skills add https://github.com/AliJ021/labelmod-core --skill postgres-alij021

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? PostgreSQL databases degrade silently through missing indexes, bloated tables, misconfigured memory, and untuned autovacuum, and diagnosing these issues requires deep operational knowledge scattered across documentation. ## Core Features & Use Cases - Query and Index Optimization: Detect unused, duplicate, and invalid indexes, rewrite SQL anti-patterns like N+1 queries and OFFSET pagination, and tune planner settings for SSD storage. - Operations and Internals Guidance: Configure MVCC/autovacuum, WAL archiving, checkpoints, streaming replication, connection pooling with PgBouncer, and backup/PITR strategies. - PlanetScale Integration: Troubleshoot connections, manage branches and deploy requests via the pscale CLI, and analyze slow queries through Insights and the MCP server. - Use Case: A production database shows rising latency. Load this Skill to find the slow queries in pg_stat_statements, identify a missing composite index, check for long transactions blocking VACUUM, and apply the fix safely. ## Quick Start Ask the assistant to review your PostgreSQL database for slow queries and unused indexes using the postgres skill.

Frequently Asked Questions about postgres

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

FAQPage Schema
How do I find unused indexes in PostgreSQL?

Query pg_stat_user_indexes joined with pg_index and filter for idx_scan = 0, excluding unique and constraint-backing indexes. Always verify stats age first and confirm with a human before dropping any index.

How to fix slow queries in PostgreSQL?

Enable pg_stat_statements to rank queries by mean execution time, then check for missing indexes, N+1 patterns, functions on indexed columns, and OFFSET pagination. Rewrite with EXISTS, cursor pagination, and composite indexes on filtered columns.

When should I use PgBouncer versus direct PostgreSQL connections?

Use PgBouncer on port 6432 for OLTP application traffic and high-concurrency workloads. Use direct connections on port 5432 for DDL, migrations, analytics, temp tables, and any session-level SET commands, since transaction pooling leaks session state.

Why does PostgreSQL run out of memory with high concurrency?

work_mem is allocated per operation, not per query, so sorts, hashes, and parallel workers multiply memory across every connection. Reduce work_mem globally, add connection pooling, and set statement_timeout to prevent OOM kills.

What causes PostgreSQL table bloat and how do I fix it?

Bloat comes from dead tuples left by UPDATE and DELETE when autovacuum cannot keep up, often due to long transactions. Tune autovacuum scale factors per table, set idle_in_transaction_session_timeout, and use REINDEX CONCURRENTLY or pg_repack for existing bloat.

When should I partition a PostgreSQL table?

Partition general tables over 100GB or 20M rows, and time-series or log tables over 50GB or 10M rows. Partitioning mainly benefits maintenance and data retention; the partition key must be part of the primary key.