maintenance_analysis
Analyze database maintenance status including indexes, vacuum, table bloat, and foreign keys. Identify unused or duplicate indexes, tables needing vacuum, and missing foreign key indexes.
Instructions
Table and index maintenance - analyzes indexes, vacuum status, table bloat, FK indexes.
LEVEL: Database ↔ Schema ↔ Table (multi-level tool)
schema='all': Database level - maintenance status for ALL schemas
schema='': Schema level - all tables in that schema (supports ANY schema name: 'sales', 'billing', 'auth', 'analytics', etc.)
table='users': Table level - specific table analysis
REQUIRED: Specify schema explicitly - use 'all' for all schemas or a specific schema name.
USE FOR: finding unused indexes, duplicate indexes, tables needing vacuum, FK missing indexes, table sizes, TOAST analysis, autovacuum status, "which indexes should I drop?". DO NOT USE FOR: live connections/locks (use database_health), slow query history (use query_performance), specific query optimization (use query_optimizer), schema structure (use get_schema), partitioned tables (use partition_analysis). STATIC: Analyzes stored statistics, not real-time activity.
ERROR RECOVERY:
"not connected": Call connect() first or pass url parameter
"schema not found": Verify schema exists with get_schema()
Large payload: Use summary_only=True or include='indexes' to filter results
"permission denied": User needs read access to pg_catalog views
INCLUDE OPTIONS:
'all': Everything (default)
'indexes': All indexes, unused indexes, duplicate indexes, tables needing indexes, largest indexes
'tables': Table statistics, hot tables (most active)
'vacuum': Bloated tables, never vacuumed, tables needing freeze, autovacuum settings
'fk_indexes': Foreign keys missing supporting indexes
'toast': TOAST storage analysis (large object storage)
Examples: maintenance_analysis() - All tables in public schema (default) maintenance_analysis(schema='all') - All schemas (database-wide) maintenance_analysis(schema='billing') - All tables in billing schema maintenance_analysis(schema='auth', table='users') - Specific table in auth schema maintenance_analysis(include='indexes') - Only index analysis maintenance_analysis(include='vacuum') - Only vacuum/bloat analysis maintenance_analysis(include='fk_indexes') - Only FK index analysis
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| include | No | What to include: 'all', 'indexes', 'tables', 'vacuum', 'fk_indexes', 'toast' | all |
| table | No | Specific table (or all tables if not specified) | |
| schema | No | Schema to analyze. Omit for all schemas, or specify one. Use get_schema() to list available. | |
| url | No | Database URL for auto-connection | |
| format | No | Output format: 'json' or 'markdown' | json |
| summary_only | No | Return only summary counts and issues, not detailed lists |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |