I recently helped a customer with a slow query. Eventually, an
ANALYZE
on a partitioned table was enough to fix the problem. This came as a surprise for the customer, since autovacuum was enabled. So I decided to write an article on how PostgreSQL collects partitioned table statistics and how they affect PostgreSQL’s estimates.
Read on to see how it works and how you can generate statistics at the table level and not just the partition level.