# Postgresql Performance

> Postgresql Performance is an Agent Skill for testing & quality published in the majiayu000/claude-skill-registry repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Optimize PostgreSQL performance - EXPLAIN ANALYZE, indexing, query tuning

- Skill name: `postgresql-performance`
- Category: [Testing & Quality](https://www.openparable.com/skill/testing-quality/1)
- Source: https://github.com/majiayu000/claude-skill-registry/blob/HEAD/skills/data/postgresql-performance/SKILL.md
- Repository: majiayu000/claude-skill-registry (498 GitHub stars when collected)

## SKILL.md

# PostgreSQL Performance Skill

> Atomic skill for query optimization

## Overview

Production-ready patterns for EXPLAIN analysis, index design, and configuration tuning.

## Prerequisites

- PostgreSQL 16+
- pg_stat_statements extension

## Parameters

```yaml
parameters:
  operation:
    type: string
    required: true
    enum: [analyze_query, create_index, tune_config, diagnose]
  target_time_ms:
    type: integer
    default: 100
```

## Quick Reference

### EXPLAIN Commands
```sql
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM users WHERE email = 'test@example.com';
```

### Index Types
| Use Case | Type | Example |
|----------|------|---------|
| Equality | B-tree | `CREATE INDEX idx ON t(col)` |
| JSONB | GIN | `USING GIN(data jsonb_path_ops)` |
| Time-series | BRIN | `USING BRIN(created_at)` |

### Key Metrics
| Metric | Healthy | Warning |
|--------|---------|---------|
| Seq Scan rows | < 10K | > 100K |
| Buffer hit | > 99% | < 95% |
| Planning time | < 10ms | > 100ms |

## Diagnostic Queries

```sql
-- Slow queries
SELECT query, mean_exec_time FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 10;

-- Unused indexes
SELECT indexrelname, idx_scan FROM pg_stat_user_indexes WHERE idx_scan = 0;

-- Table bloat
SELECT tablename, n_dead_tup FROM pg_stat_user_tables WHERE n_dead_tup > 10000;
```

## Troubleshooting

| Problem | Cause | Solution |
|---------|-------|----------|
| Seq Scan | Missing index | Create index |
| High buffer reads | Cold cache | Increase shared_buffers |
| Wrong estimates | Stale stats | Run ANALYZE |

## Usage

```
Skill("postgresql-performance")
```

---

Source: https://www.openparable.com/skill/testing-quality/postgresql-performance (OpenParable). Cite the canonical URL above.
