Find unused indexes in PostgreSQL
Use pg_stat_user_indexes to find indexes with no recorded scans, then review whether the workload still needs them.
This query excludes unique, primary, invalid, and constraint-owned indexes:
SELECT s.schemaname, s.relname AS table_name, s.indexrelname AS index_name, s.idx_scan, pg_size_pretty(pg_relation_size(s.indexrelid)) AS index_sizeFROM pg_stat_user_indexes AS sJOIN pg_index AS i ON i.indexrelid = s.indexrelidWHERE s.idx_scan = 0 AND NOT i.indisunique AND NOT i.indisprimary AND i.indisvalid AND NOT EXISTS ( SELECT 1 FROM pg_constraint AS c WHERE c.conindid = s.indexrelid )ORDER BY pg_relation_size(s.indexrelid) DESC;The largest candidates appear first. A zero count means no scans were recorded in the available history; it does not prove an index is unnecessary. See PostgreSQL’s statistics reference.
Find unused indexes in PostgreSQL with TableAI
Section titled “Find unused indexes in PostgreSQL with TableAI”- Open Admin › Indexes.
- Select Unused only to focus the list.
- Select an index to inspect its columns, size, and scan count.
- Review candidates against the SQL checks above.

Before removing an index:
- Include scheduled reports and infrequent tasks in the observed workload.
- Check for recent index creation or statistics resets.
- Compare plans for queries that could use it.
- Save its definition so an approved removal can be reversed by recreating it.
Remove an index only after reviewing its purpose. Queries can slow down when their index is removed. Use change structure for the SQL preview and confirmation workflow.
Required privileges
Section titled “Required privileges”No extension is required. Your role needs access to index statistics and catalogs; removal requires ownership or appropriate administrator authority. If access fails, follow Admin data unavailable.