postgresql-optimization

Analyze EXPLAIN ANALYZE output to optimize PostgreSQL queries and configuration.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/CenredJun/openclaw-claudecode-setup-kit --skill postgresql-optimization-cenredjun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-optimization
Source: https://github.com/CenredJun/openclaw-claudecode-setup-kit/tree/main/skills/postgresql-optimization
Command: npx skills add https://github.com/CenredJun/openclaw-claudecode-setup-kit --skill postgresql-optimization-cenredjun

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PostgreSQL optimization reduces slow query latency, excessive resource usage, and operational instability caused by poor indexes, suboptimal queries, and misconfigured server settings.

Core Features & Use Cases

  • Query Plan Analysis: Interpret EXPLAIN / EXPLAIN ANALYZE output to identify sequential scans, inefficient joins, and costly sorts.
  • Indexing & Schema: Recommend B-tree, GIN, GiST, BRIN, partial and expression indexes and schema choices that improve read/write performance.
  • Production Tuning: Advise memory settings, autovacuum, WAL/checkpoint tuning, connection pooling with PgBouncer, and partitioning strategies for large tables.
  • Use Case: Diagnose a slow customer-report query, propose index and query rewrites, suggest configuration changes for a 32GB server, and outline safe rollout steps.

Quick Start

Analyze the output of EXPLAIN (ANALYZE, BUFFERS) for a slow query and recommend specific index, rewrite, or configuration changes to improve latency.

Frequently Asked Questions about postgresql-optimization

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

FAQPage Schema
How do I use EXPLAIN ANALYZE to diagnose slow PostgreSQL queries?

Use EXPLAIN ANALYZE to interpret query plans, identifying sequential scans, inefficient joins, and costly sorts causing slow PostgreSQL queries. This analysis exposes execution bottlenecks, enabling targeted index creation and query rewrites to reduce latency and resource consumption.

What are the best PostgreSQL indexes to improve read and write performance?

The best PostgreSQL indexes for performance include B-tree, GIN, GiST, BRIN, partial, and expression indexes. Proper index design and schema choices accelerate read operations while minimizing write overhead, significantly lowering query latency for both OLTP and analytical workloads.

How do I tune PostgreSQL configuration and connection pooling for a 32GB server?

Tune PostgreSQL configuration by adjusting memory settings, autovacuum, WAL, and checkpoints, while implementing connection pooling with PgBouncer. These optimizations stabilize operations, reduce resource consumption, and safely support high-concurrency workloads on a 32GB production server.

When should I use partitioning strategies for large PostgreSQL tables?

Use PostgreSQL partitioning strategies for large tables to improve query latency and simplify data management. Partitioning physically divides massive tables into smaller segments, enabling faster scans and reduced resource consumption for analytical and time-based workloads.

How does pg_stat_statements help with PostgreSQL query optimization?

pg_stat_statements helps PostgreSQL query optimization by tracking execution statistics for all queries. Analyzing this data identifies the most time-consuming and resource-intensive queries, prioritizing which slow statements require EXPLAIN ANALYZE, index adjustments, or query rewrites.

Can PgBouncer and pg_partman be used together for production PostgreSQL tuning?

PgBouncer and pg_partman work together for production PostgreSQL tuning by managing connection pooling and automating partition maintenance. This combination reduces connection overhead and handles large table partitioning, lowering latency and stabilizing high-throughput environments.