Analyze table bloat
analyze_table_bloatIdentify and rank tables and indexes by bloat percentage, worst first. Uses catalog estimates by default; enable precise mode for exact pgstattuple analysis.
Instructions
Rank a schema's tables and indexes by estimated bloat, worst first. By default uses a cheap catalog-only estimate (relpages vs a reltuples/row-width floor) plus the dead-tuple ratio from pg_stat_user_tables. Set precise=true to use pgstattuple / pgstatindex for an exact (but I/O-heavy) read when the extension is installed — it falls back to the estimate and reports method='estimate' if it isn't. Returns tables and indexes (each capped at limit) with per-object est_bloat_pct, plus available and method.
Example: analyze_table_bloat(schema='public', limit=20, precise=false)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| schema | Yes | ||
| precise | No | ||
| database | No | Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| detail | Yes | ||
| method | Yes | ||
| schema | Yes | ||
| tables | Yes | ||
| indexes | Yes | ||
| available | Yes |