From ed314a6b257d22fe21b2d13fc52a5d3fe16137b0 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Thu, 22 Jul 2021 16:06:18 -0500 Subject: [PATCH 1/3] documentation deficiencies for ANALYZE of partitioned tables This is partially extracted from 1b5617eb844cd2470a334c1d2eec66cf9b39c41a, which was reverted. --- doc/src/sgml/maintenance.sgml | 27 ++++++++++++++++++++++++++ doc/src/sgml/ref/analyze.sgml | 36 ++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index 36f975b1e5b..b7c806cc906 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -290,6 +290,14 @@ to meaningful statistical changes. + + Tuples changed in partitions and inheritance children do not count towards + analyze on the parent table. If the parent table is empty or rarely + changed, it may never be processed by autovacuum. It is necessary to + periodically manual run ANALYZE on the parent table to + keep the statistics of its table hierarchy up to date. + + As with vacuuming for space recovery, frequent updates of statistics are more useful for heavily-updated tables than for seldom-updated @@ -347,6 +355,18 @@ ANALYZE commands on those tables on a suitable schedule. + + + + The autovacuum daemon does not issue ANALYZE commands for + partitioned tables. Inheritance parents will only be analyzed if the + parent itself is changed - changes to child tables do not trigger + autoanalyze on the parent table. It is necessary to periodically run a + manual ANALYZE to keep the statistics of the table + hierarchy up to date. + + + @@ -819,6 +839,13 @@ analyze threshold = analyze base threshold + analyze scale factor * number of tu since the last ANALYZE. + + Partitioned tables are not processed by autovacuum. Statistics + should be collected by running a manual ANALYZE when it is + first populated, and updated whenever the distribution of data in its + partitions changes significantly. + + Temporary tables cannot be accessed by autovacuum. Therefore, appropriate vacuum and analyze operations should be performed via diff --git a/doc/src/sgml/ref/analyze.sgml b/doc/src/sgml/ref/analyze.sgml index c423aeeea5e..3bf904e36f9 100644 --- a/doc/src/sgml/ref/analyze.sgml +++ b/doc/src/sgml/ref/analyze.sgml @@ -250,22 +250,32 @@ ANALYZE [ VERBOSE ] [ table_and_columns - If the table being analyzed has one or more children, - ANALYZE will gather statistics twice: once on the - rows of the parent table only, and a second time on the rows of the - parent table with all of its children. This second set of statistics - is needed when planning queries that traverse the entire inheritance - tree. The autovacuum daemon, however, will only consider inserts or - updates on the parent table itself when deciding whether to trigger an - automatic analyze for that table. If that table is rarely inserted into - or updated, the inheritance statistics will not be up to date unless you - run ANALYZE manually. + If the table being analyzed is partitioned, ANALYZE + will gather statistics by sampling blocks randomly from its partitions; + in addition, it will recurse into each partition and update its statistics. + (However, in multi-level partitioning scenarios, each leaf partition + will only be analyzed once.) + By constrast, if the table being analyzed has inheritance children, + ANALYZE will gather statistics for it twice: + once on the rows of the parent table only, and a second time on the + rows of the parent table with all of its children. This second set of + statistics is needed when planning queries that traverse the entire + inheritance tree. The child tables themselves are not individually + analyzed in this case. - If any of the child tables are foreign tables whose foreign data wrappers - do not support ANALYZE, those child tables are ignored while - gathering inheritance statistics. + The autovacuum daemon does not process partitioned tables, nor does it + process inheritance parents due to modifications to its child tables. + It is usually necessary to periodically run a manual + ANALYZE to keep the statistics of the table hierarchy + up to date. + + + + If any child tables or partitions are foreign tables whose foreign + data wrappers do not support ANALYZE, those tables are + ignored while gathering inheritance statistics. -- 2.17.1