PostgreSQL

High sequential scan count may indicate missing indexes requiring query optimization

warning
performanceUpdated Sep 21, 2023
Technologies:
How to detect:

Large values in pg_stat_user_tables.seq_scan column indicate potential missing indexes. The severity depends on time window (statistics collection period since stats_reset) and correlation with high total_exec_time queries in pg_stat_statements. Sequential scans of millions of rows over short periods warrant investigation.

Recommended action:

1. Check statistics collection period with 'SELECT datname, stats_reset FROM pg_stat_database' to contextualize seq_scan values. 2. Query pg_stat_user_tables with 'SELECT relname, seq_scan, seq_tup_read / seq_scan AS tup_per_scan FROM pg_stat_user_tables WHERE seq_scan > 0' to identify high seq_scan tables. 3. Correlate findings with pg_stat_statements queries that have highest total_exec_time. 4. Review execution plans for top queries involving high seq_scan tables to determine if adding indexes would reduce resource consumption.