Search code examples
postgresqlamazon-rds

Postgres ANALYZE is not analyzing all pages


We have recently done a significant upgrade of our Postgres DB in AWS RDS. As part of the update steps, we performed ANALYZE VERBOSE command, so the database scans all tables. However, we observed that a few tables which contain extensive data are not fully analyzed. Output statement says like this "": scanned 30000 of 609920 pages, containing 560268 live rows and 35063 dead rows; 30000 rows in sample, 11390622 estimated total rows".

Will it be a problem if we don't scan the remaining pages? If yes, how do we scan them?


Solution

  • No, that is no problem. ANALYZE collects data from a statistically significant sample of the table rows, because it only collects statistical data.

    If you consider the statistics too coarse, you can increase default_statistics_target so that PostgreSQL collects more detailed data and consequently uses a bigger sample. Be warned, though, that that will increase the planning time for all queries.