benbjohnson/litestream · warning

get final size: %w

Error message

get final size: %w

What it means

At the end of shrinkDatabase, the final database size is measured with getDatabaseSize(c.DB) to compute the reduction percentage; failure is wrapped as `get final size: %w`. This is a pure filesystem/stat operation — all SQL work (deletes, checkpoint, vacuum) has already completed, so this error never means the shrink itself failed.

Source

Thrown at cmd/litestream-test/shrink.go:134

			"change_from_delete_mb", (sizeAfterDelete-sizeAfterCheckpoint)/1024/1024,
		)
	}

	if c.Vacuum {
		if err := c.runVacuum(db); err != nil {
			return fmt.Errorf("vacuum: %w", err)
		}

		sizeAfterVacuum, _ := getDatabaseSize(c.DB)
		slog.Info("Size after VACUUM",
			"size_mb", sizeAfterVacuum/1024/1024,
			"total_reduction_mb", (initialSize-sizeAfterVacuum)/1024/1024,
		)
	}

	finalSize, err := getDatabaseSize(c.DB)
	if err != nil {
		return fmt.Errorf("get final size: %w", err)
	}

	reductionPercent := float64(initialSize-finalSize) / float64(initialSize) * 100
	slog.Info("Shrink operation complete",
		"initial_size_mb", initialSize/1024/1024,
		"final_size_mb", finalSize/1024/1024,
		"reduction_percent", fmt.Sprintf("%.1f", reductionPercent),
	)

	return nil
}

func (c *ShrinkCommand) getTableList(db *sql.DB) ([]string, error) {
	rows, err := db.Query(`
		SELECT name FROM sqlite_master
		WHERE type='table'
		AND name NOT LIKE 'sqlite_%'
		AND name NOT LIKE 'load_test'

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Re-run to get a clean summary; the shrink work itself already succeeded
  2. Verify with `ls -l <db>` / `du -h <db>` to get the final size manually
  3. Prevent cleanup jobs from racing the tool (delay deletion until the process exits)
  4. Inspect the wrapped inner error for the exact filesystem cause
Defensive patterns

Strategy: fallback

Validate before calling

// size can always be obtained manually if the tool's final stat fails:
// ls -l <db>  or  sqlite3 <db> 'PRAGMA page_count * page_size;'

Try / catch

if err := runShrink(args); err != nil {
    if strings.Contains(err.Error(), "get final size") {
        log.Printf("shrink completed but final measurement failed (non-fatal): %v", err)
        return nil // work is done; only reporting failed
    }
    return err
}

Prevention

When it happens

Trigger: The database file vanished or became unreadable between the last operation and this final stat (external deletion, unmounted volume, permissions change); an OS error inside getDatabaseSize.

Common situations: Cleanup automation firing at job completion and deleting temp databases before the tool logs its summary; tests running on ephemeral storage that gets recycled; a hung NFS mount timing out on the final stat.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/09bc0603853ebe00. Report an issue: GitHub.