postgresql-query-optimization

Analyze PostgreSQL execution plans with EXPLAIN ANALYZE and recommend index strategies.

Updated Feb 19, 2026
One-click install
npx skills add https://github.com/rudi-bruchez/dba-skills --skill postgresql-query-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-query-optimization
Source: https://github.com/rudi-bruchez/dba-skills/tree/main/skills/postgresql-query-optimization
Command: npx skills add https://github.com/rudi-bruchez/dba-skills --skill postgresql-query-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill addresses slow-running PostgreSQL queries by providing a systematic approach to identify, diagnose, and resolve performance bottlenecks.

Core Features & Use Cases

  • Identify Slow Queries: Uses pg_stat_statements and pg_stat_activity to pinpoint expensive queries.
  • Analyze Execution Plans: Leverages EXPLAIN ANALYZE to understand query execution flow and identify costly operations.
  • Index Optimization: Recommends and creates appropriate B-tree, GIN, GiST, or BRIN indexes, including partial and covering indexes.
  • Statistics Tuning: Guides on updating table statistics and setting extended statistics for correlated columns.
  • Configuration Adjustments: Provides recommendations for key PostgreSQL parameters like random_page_cost, work_mem, and effective_cache_size.
  • Use Case: An application is experiencing slow response times. This Skill can analyze the database activity, identify the top offending queries, explain their execution plans, and suggest specific index creations or configuration changes to improve performance.

Quick Start

Use the postgresql-query-optimization skill to analyze and optimize the slow query SELECT * FROM orders WHERE customer_id = 123;.

Frequently Asked Questions about postgresql-query-optimization

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

FAQPage Schema
How do I optimize slow PostgreSQL queries using EXPLAIN ANALYZE?

To optimize slow PostgreSQL queries, you analyze execution plans with EXPLAIN ANALYZE to identify costly operations like sequential scans and join inefficiencies, then apply targeted index strategies and configuration tuning to resolve the bottlenecks.

What's the best way to identify expensive PostgreSQL queries for performance tuning?

The best way to identify expensive queries for PostgreSQL performance tuning is by querying pg_stat_statements and pg_stat_activity to pinpoint the slowest database operations consuming the most resources.

When should I use GIN, GiST, or BRIN indexes in PostgreSQL?

You should choose GIN, GiST, or BRIN indexes in PostgreSQL when standard B-tree indexes are insufficient, applying partial or covering indexes to match specific query patterns and improve execution plan efficiency.

Why does my PostgreSQL query have poor row estimates and sequential scans?

Poor row estimates and sequential scans in PostgreSQL often occur because table statistics are outdated or correlated columns lack extended statistics, causing the query planner to choose inefficient execution paths.

Does this query optimization approach work with PostgreSQL 13 and newer versions?

Yes, this query optimization approach works with PostgreSQL version 13 and newer, diagnosing execution plan issues and adjusting configuration parameters like random_page_cost, work_mem, and effective_cache_size for those environments.