PostgreSQL Performance Optimization

PostgreSQL Performance Optimization is a skill for Claude Code, Codex from bobmatnyc/mcp-skillset. It costs 47 tokens per session (2,969 once invoked), scanned A, original, MIT.

A guide for improving PostgreSQL database performance through query tuning, indexes, schema design, and pgvector. PostgreSQL is a database system, while pgvector adds similarity search for numerical representations used in AI features.

In plain words
What is it for?
Use it to analyze query plans with EXPLAIN, design indexes and schemas, optimize SQLAlchemy or Django ORM code, support high-concurrency systems, and add vector search.
Why use it?
It helps find why database queries are slow, reduce delays under heavy use, and choose suitable designs for data-intensive applications.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/bobmatnyc/mcp-skillset/postgresql-optimization
Any agent
npx skills add bobmatnyc/mcp-skillset --skill postgresql-optimization
Clone the repo
git clone --depth 1 https://github.com/bobmatnyc/mcp-skillset

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for PostgreSQL Performance Optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/bobmatnyc/mcp-skillset/postgresql-optimization.svg)](https://agentmods.dev/skills/bobmatnyc/mcp-skillset/postgresql-optimization)
Your own site
<a href="https://agentmods.dev/skills/bobmatnyc/mcp-skillset/postgresql-optimization"><img src="https://agentmods.dev/badge/skills/bobmatnyc/mcp-skillset/postgresql-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 47 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,969 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00047 $0.02969
Opus 5 $0.00023 $0.01484
Sonnet 5 $0.00009 $0.00594
Haiku 4.5 $0.00005 $0.00297

Measured 6d ago against content hash 0b94cf62db81, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

PostgreSQL Performance Optimization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/skill-templates/postgresql-optimization/SKILL.md · 387 lines

How it starts

The opening of the file, as written. The whole thing — 387 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PostgreSQL Performance Optimization

Overview

Master PostgreSQL performance optimization with modern techniques for query tuning, indexing, and AI/ML workloads. With 55% of Postgres developers adopting AI tools in 2024, understanding pgvector and performance optimization is critical for building scalable data-intensive applications.

When to Use This Skill

  • Slow queries requiring optimization (>100ms response time)
  • Designing database schemas for high-performance applications
  • Implementing vector similarity search for AI/ML features
  • Scaling PostgreSQL for high-concurrency workloads
  • Migrating from NoSQL to PostgreSQL for better consistency
  • Optimizing ORMs (SQLAlchemy, Django ORM) for production

Core Principles

1. EXPLAIN ANALYZE is Your Best Friend

-- ALWAYS use EXPLAIN ANALYZE for slow queries
EXPLAIN (ANALYZE, BUFFERS, VERBOSE, COSTS, TIMING)
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '30 days'
GROUP BY u.id, u.name
ORDER BY order_count DESC
LIMIT 100;

-- Read output top-to-bottom, focus on:
-- 1. Seq Scan (bad for large tables) vs Index Scan (good)
-- 2. Actual time vs Planning time
-- 3. Rows estimates vs actual rows
-- 4. Buffers (disk I/O indicators)

Key Metrics:

  • Planning Time: How long query planner took (<10ms ideal)
  • Execution Time: Actual query runtime (<100ms for OLTP)
  • Rows: Estimated vs actual (mismatches indicate stale statistics)
  • Buffers: Shared hits (good), reads (disk I/O, slow)

2. Indexing Strategy

-- B-Tree Index (default, most common)
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);

-- Partial Index (smaller, faster for filtered queries)
CREATE INDEX idx_active_users ON users(email)
WHERE is_active = true AND deleted_at IS NULL;

-- Covering Index (includes extra columns to avoid table lookups)
CREATE INDEX idx_orders_covering ON orders(user_id, status)
INCLUDE (created_at, total_amount);

-- GIN Index (for full-text search, JSONB, arrays)
CREATE INDEX idx_products_search ON products
USING GIN (to_tsvector('english', name || ' ' || description));

CREATE INDEX idx_tags_gin ON posts USING GIN(tags);

-- GiST Index (for geometric data, ranges, full-text)
CREATE INDEX idx_locations_gist ON stores
USING GIST (location);

-- BRIN Index (block range, time-series data)
CREATE INDEX idx_logs_created ON logs USING BRIN(created_at);

Read the full file on GitHub · 387 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 387 lines · 47 tokens per session scan A 0b94cf62db81

Subscribe to this mod's changes

PostgreSQL Performance Optimization is a skill published in the GitHub repository bobmatnyc/mcp-skillset (20 stars, last pushed 5mo ago), licensed MIT. It adds 47 tokens to every session and 2,969 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories