osbuild-service-maintenance: Vacuum tables

Call vacuum analyze after each chunk of updates, and dump vacuum stats
at the beginning and end of the db cleanup.

Nulling results can increase size on disk, but calling vacuum analyze
will free up space within the table (not on disk) and reuse the space
for new inserts and updates.
This commit is contained in:
Sanne Raymaekers 2022-06-07 13:12:14 +02:00 committed by Ondřej Budai
parent 8bfc6c9961
commit ff408aa68f
2 changed files with 89 additions and 0 deletions

View file

@ -22,6 +22,11 @@ func DBCleanup(dbURL string, dryRun bool, cutoff time.Time) error {
return fmt.Errorf("Error querying jobs: %v", err)
}
err = jobs.LogVacuumStats()
if err != nil {
logrus.Errorf("Error running vacuum stats: %v", err)
}
for k, v := range jobsByType {
logrus.Infof("Deleting results from %d %s jobs", len(v), k)
if dryRun {
@ -42,8 +47,17 @@ func DBCleanup(dbURL string, dryRun bool, cutoff time.Time) error {
continue
}
logrus.Infof("Deleted results from %d jobs out of %d job ids", rows, len(v))
err = jobs.VacuumAnalyze()
if err != nil {
logrus.Errorf("Error running vacuum analyze: %v", err)
}
}
}
err = jobs.LogVacuumStats()
if err != nil {
logrus.Errorf("Error running vacuum stats: %v", err)
}
return nil
}