pg-index-optimization

pg-index-optimization is a skill for Claude Code, Codex from isdaniel/pgtuner_mcp. It costs 44 tokens per session (3,048 once invoked), scanned A, original, Apache-2.0.

A guide for reviewing and improving indexes in PostgreSQL, the open-source relational database.

In plain words
What is it for?
It finds unused or duplicate indexes, recommends missing ones, and tests proposed indexes hypothetically before production changes.
Why use it?
It helps address slow queries, unnecessary storage use, duplicate indexes, and slower writes caused by excessive indexing.

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/isdaniel/pgtuner_mcp/pg-index-optimization
Any agent
npx skills add isdaniel/pgtuner_mcp --skill pg-index-optimization
Clone the repo
git clone --depth 1 https://github.com/isdaniel/pgtuner_mcp

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 pg-index-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/isdaniel/pgtuner_mcp/pg-index-optimization.svg)](https://agentmods.dev/skills/isdaniel/pgtuner_mcp/pg-index-optimization)
Your own site
<a href="https://agentmods.dev/skills/isdaniel/pgtuner_mcp/pg-index-optimization"><img src="https://agentmods.dev/badge/skills/isdaniel/pgtuner_mcp/pg-index-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 44 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,048 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.00044 $0.03048
Opus 5 $0.00022 $0.01524
Sonnet 5 $0.00009 $0.00610
Haiku 4.5 $0.00004 $0.00305

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

Security

Grade A, and why

pg-index-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.

skills/pg-index-optimization/SKILL.md · 377 lines

How it starts

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

PostgreSQL Index Optimization

This skill guides comprehensive index analysis and optimization for PostgreSQL databases using pgtuner-mcp tools, including HypoPG hypothetical index testing.

When to Use This Skill

Use this skill when the user:

  • Asks to optimize or review database indexes
  • Wants to find and remove unused or duplicate indexes
  • Reports slow queries that might benefit from better indexing
  • Asks "what indexes should I create?" or "which indexes can I drop?"
  • Mentions high storage usage from indexes or slow write performance
  • Wants to test index ideas without creating them in production

MCP Resources Available

  • pgtuner://docs/tools -- Full tool reference documentation
  • pgtuner://table/{schema}/{table_name}/indexes -- Quick view of existing indexes on a table (lightweight)
  • pgtuner://table/{schema}/{table_name}/stats -- Table statistics for context
  • pgtuner://query/{query_hash}/stats -- Per-query stats to understand which queries benefit from indexes

This skill corresponds to the index_optimization MCP Prompt. If the user triggers that prompt, follow this skill's workflow.

Prerequisites

  • The pgtuner-mcp server must be connected with a valid DATABASE_URI
  • Required: pg_stat_statements extension for workload analysis
  • Recommended: hypopg extension for hypothetical index testing
  • Recommended: pgstattuple extension for index bloat analysis

Pre-Flight Checks

Before starting, check extension availability:

  1. Use manage_hypothetical_indexes with action: "check" to verify HypoPG. If unavailable, skip Phase 3 (hypothetical testing) and rely on heuristic-based recommendations.
  2. If analyze_index_bloat returns an error about pgstattuple, note that bloat measurements will be estimated rather than exact.

Agent Decision Tree

User asks about indexes
  |
  +--> "Which indexes can I drop?"
  |    --> Start with Phase 1 (cleanup), focus on Step 1.1
  |
  +--> "What indexes should I create?"
  |    --> Start with Phase 2 (missing indexes)
  |
  +--> "Comprehensive index review"
  |    --> Follow all 4 phases in order
  |
  +--> "Test a specific index idea"
  |    --> Skip to Phase 3 (hypothetical testing)
  |
  +--> After finding unused indexes, also check:
       --> Read pgtuner://table/{schema}/{table}/indexes for quick context
       --> Cross-reference: are the "unused" indexes UNIQUE? (warn user)
       --> Cross-reference: how long has the DB been up?

Read the full file on GitHub · 377 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 · 377 lines · 44 tokens per session scan A d58d563b9d27

Subscribe to this mod's changes

pg-index-optimization is a skill published in the GitHub repository isdaniel/pgtuner_mcp (28 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 44 tokens to every session and 3,048 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

exasol-mcp-server

Exasol MCP Server usage guide: common workflows for database exploration, query debugging, BucketFS management, and working with UDFs and preprocessors.

exasol/mcp-server · 36 tokens

tencent-pg-slowquery-diagnosis

Diagnose slow SQL and performance anomalies for Tencent Cloud PostgreSQL by calling Tencent Cloud OpenAPI directly. This skill can use the full aligned PostgreSQL OpenAPI action set documented in @references/apireference.md. Start with evidence collection first, and require explicit confirmation before any write…

TencentCloudCommunity/mcp-server · 75 tokens

safe-sql-execution

Use whenever code will build, return, fetch, or execute SQL that runs against a user's real Postgres database — even when the request reads like an ordinary feature or bug fix and never says "security," "injection," or "SafeSqlFragment." This covers: writing or editing any pg-meta function, query builder, or endpoint…

supabase/supabase · 221 tokens

write-the-docs

Draft new or updated Supabase docs content for a feature or launch, grounded in product intent (Linear when available), a read of the actual code, and the docs style guide once one exists. Use when asked to write docs for a new feature, a product launch, or a Linear ticket that needs net-new content rather than a bug…

supabase/supabase · 104 tokens

amazon aurora dsql

Deprecated compatibility redirect for Aurora DSQL guidance. Use when a request concerns DSQL, Aurora DSQL, distributed SQL, DSQL schemas, migrations, queries, authentication, performance, or application development.

awslabs/mcp · 46 tokens

fix-bug

Use when given a GitHub issue URL or number to investigate and implement a fix. Triggers on "fix issue", "fix bug", "fix.

bytebase/dbhub · 34 tokens