StartPeriodicVacuum runs full VACUUM on a schedule to reclaim space and defragment. VACUUM acquires an exclusive lock and blocks all database operations briefly.
(db *gorm.DB, interval time.Duration)
| 125 | // StartPeriodicVacuum runs full VACUUM on a schedule to reclaim space and defragment. |
| 126 | // VACUUM acquires an exclusive lock and blocks all database operations briefly. |
| 127 | func StartPeriodicVacuum(db *gorm.DB, interval time.Duration) { |
| 128 | go func() { |
| 129 | ticker := time.NewTicker(interval) |
| 130 | defer ticker.Stop() |
| 131 | |
| 132 | for range ticker.C { |
| 133 | if err := db.Exec("VACUUM").Error; err != nil { |
| 134 | log.ErrorWrap(err, "VACUUM failed") |
| 135 | } |
| 136 | } |
| 137 | }() |
| 138 | } |