Hard java backend

Fresh statistics (ANALYZE) and autovacuum tuning against bloat

The 30 second answer

The planner chooses plans from table statistics. If they are stale after big data changes, it misjudges row counts and picks bad plans, so I run ANALYZE or let autovacuum do it. Autovacuum also cleans dead rows left by updates and deletes. On busy tables I tune it to run more often, otherwise bloat grows and every scan gets slower.

The planner picks plans from statistics, and stale stats give bad plans. VACUUM reclaims space from dead rows left by UPDATE and DELETE, and updates the visibility map. Autovacuum triggers on autovacuum_vacuum_scale_factor (default 0.2, so 20% of rows). On big, busy tables you lower it per table.

ALTER TABLE orders SET (autovacuum_vacuum_scale_factor = 0.02, autovacuum_analyze_scale_factor = 0.01);
Sources (3)
  1. PostgreSQL 17: ANALYZE
  2. Routine Vacuuming
  3. Autovacuum settings