A schedule is not proof that the job ran
The fixture has 6,667 live and 3,333 deleted versions. The alert query compares the unrounded estimated dead fraction with 0.20 and rounds only the display. Treat the alert as an investigation trigger, not measured physical bloat or an instruction to run VACUUM FULL.
A script needs an interpreter, execute permission, explicit connection parameters and visible failure. set -e stops shell failures; psql -v ON_ERROR_STOP=1 makes an SQL error fail the client. >> ... 2>&1 appends both output streams for diagnosis.
* * * * * is a once-per-minute training schedule even though the file is named weekly_maintenance.sh. sudo cron starts the root scheduler; the crontab job runs as its owner. Clear the manual log before starting it and require a fresh entry. Polling is bounded at 75 seconds, and later cleanup stops this training schedule before the load experiment.
The post-load hook inserts 5,000 rows, stops on failure, then analyses the table; expect 11,667 total. Production autovacuum should normally remain enabled, and maintenance cadence follows workload rather than a universal weekly recipe.
Did you know? Autovacuum never schedules VACUUM FULL: its aim is regular space reuse so a full rewrite is rarely needed. Routine vacuuming.
Key concepts
Why crond Needs Root Here Specifically
The root scheduler reads its protected schedule files and switches to each job owner. crontab installs or lists the student schedule; sudo cron starts the scheduler. Job commands run as the crontab owner, not automatically as root.
Scheduled Maintenance vs Event-Triggered Maintenance
A weekly VACUUM ANALYZE via cron is scheduled: it runs on a clock, regardless of what happened since the last run. A post-bulk-load ANALYZE hook is event-triggered: it runs because a specific event (the load finishing) just happened, independent of any clock. Both matter, and neither substitutes for the other — a schedule cannot know a bulk load just happened, and an event hook cannot catch slow, steady bloat that accumulates between distinct events.