May 2018
Intermediate to advanced
576 pages
30h 25m
English
We saw the pg_relation_size() function earlier, so we know it brings back an accurate value for the current size of the table.
When we vacuum a table in Postgres, we record two pieces of information in the pg_class catalog entry for the table. These two items are the number of data blocks in the table (relpages) and the number of rows in the table (reltuples). Some people think they can use the value of reltuples in pg_class as an estimate, but it could be severely out of date. You will also be fooled if you use information in another table named pg_stat_user_tables, which is discussed in more detail in Chapter 10, Performance and Concurrency.
The Postgres optimizer uses the relpages and reltuples values to calculate the average ...