Find unused objects
find_unused_objectsDetect tables and indexes with zero scan counts since last pg_stat reset to identify potentially unused objects, excluding primary key and unique indexes.
Instructions
Find tables and indexes with zero scans since pg_stat was last reset — a strong signal of dead code, but NOT a verdict. Tables report seq+idx scan counts, write counts, and estimated row count; indexes report size and definition. Excludes PRIMARY KEY and UNIQUE indexes (PG needs those regardless of scans). Run this after the database has been hot for a meaningful period — fresh stats produce false positives. Returns an object with tables (list of candidate tables with their stats) and indexes (list of candidate indexes with size and definition).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | Yes | ||
| 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 |
|---|---|---|---|
| schema | Yes | ||
| tables | Yes | ||
| indexes | Yes |