FULL AI ANALYSIS

PostgreSQL bulk INSERT throughput collapses on partitioned table after stats collector restart

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

The planner relies on pg_statistic data populated by ANALYZE to choose efficient plans. Restarting the stats collector alone should not destroy stats, but if stats were lost or partition-level statistics were not present for new partitions, the planner fell back to generic or default estimates leading to suboptimal plans and slower imports. Manual ANALYZE immediately restored correct stats and performance. Autovacuum may not be aggressive enough to populate stats quickly under heavy data inflow, particularly when new partitions are created and filled rapidly.

Possible causes

Partition-level pg_statistic entries missing or stale after stats collector restart, causing poor cardinality estimates

95%

Autovacuum/analyze thresholds too high for high-volume partition loads so ANALYZE not run promptly on new partitions

45%

Import pattern (COPY + concurrent DDL or partition creation) suppresses automatic ANALYZE triggers until threshold reached

25%

Visibility map or statistics corruption during maintenance caused planner to use fallback estimates

15%

Suggested fixes

1

Diagnostic step 1

Automate running ANALYZE on new partitions immediately after creation or as part of the partition-creation job to ensure stats exist before heavy data load.

2

Diagnostic step 2

Lower autovacuum_analyze_scale_factor or add targeted autovacuum/analyze settings for the partitioned table to trigger ANALYZE sooner on large inserts; test in staging for overhead tradeoffs.

3

Diagnostic step 3

If maintenance requires restarting stats collector or PostgreSQL, schedule a post-maintenance ANALYZE run for affected schemas and partitions as standard operating procedure.

4

Diagnostic step 4

Consider using pg_prewarm or warming queries to prime planner statistics after maintenance, and monitor pg_stat_all_tables to ensure last_analyze timestamps are updated. Escalate to DBA team if statistics appear corrupted and cannot be regenerated; avoid dropping pg_statistic manually.