Skip to content

Commit db8affa

Browse files
committed
Add disk space check before VACUUM to prevent failures
Problem: - VACUUM INTO ran out of disk space (15GB volume, needed 18GB) - Created partial frontpage_new.sqlite (5.5GB) before failing - Left incomplete files requiring manual cleanup Solution: Add pre-flight disk space check: - Calculates required space (~90% of current DB size) - Checks available space using statfs - Skips VACUUM if insufficient space - Logs warning with specific space requirements Example log output: "Insufficient disk space for VACUUM - skipping" free_space_gb=5.2 required_gb=9.0 db_size_gb=10.0 action="Increase volume size before next VACUUM" Manual cleanup needed: rm /data/frontpage_new.sqlite rm /data/frontpage_new.sqlite-journal fly volumes extend <volume-id> --size 25 After volume expansion, next Sunday's VACUUM will succeed.
1 parent 7066ee4 commit db8affa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

archive.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"sync"
10+
"syscall"
1011
"time"
1112

1213
pond "github.com/alitto/pond/v2"
@@ -539,6 +540,34 @@ func (app app) vacuumWorker(ctx context.Context) {
539540
continue
540541
}
541542

543+
// Check available disk space before attempting VACUUM
544+
// VACUUM INTO needs space for both old and new database
545+
dbPath := fmt.Sprintf("%s/frontpage.sqlite", app.ndb.sqliteDataDir)
546+
var dbSize int64
547+
if stat, err := os.Stat(dbPath); err == nil {
548+
dbSize = stat.Size()
549+
}
550+
551+
// Check free space on volume
552+
var statfs syscall.Statfs_t
553+
if err := syscall.Statfs(app.ndb.sqliteDataDir, &statfs); err == nil {
554+
freeSpace := int64(statfs.Bavail) * int64(statfs.Bsize)
555+
requiredSpace := int64(float64(dbSize) * 0.9) // Need ~90% of DB size for compacted copy
556+
557+
if freeSpace < requiredSpace {
558+
logger.Warn("Insufficient disk space for VACUUM - skipping",
559+
"free_space_gb", float64(freeSpace)/(1024*1024*1024),
560+
"required_gb", float64(requiredSpace)/(1024*1024*1024),
561+
"db_size_gb", float64(dbSize)/(1024*1024*1024),
562+
"action", "Increase volume size before next VACUUM")
563+
continue
564+
}
565+
566+
logger.Info("Disk space check passed",
567+
"free_space_gb", float64(freeSpace)/(1024*1024*1024),
568+
"required_gb", float64(requiredSpace)/(1024*1024*1024))
569+
}
570+
542571
// Perform VACUUM INTO (creates compacted copy)
543572
err = app.performWeeklyVacuum(ctx)
544573
if err != nil {

0 commit comments

Comments
 (0)