more logging
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-23 11:02:30 +11:00
parent 3671860b7d
commit 871d7c2024
4 changed files with 108 additions and 6 deletions

View File

@@ -33,11 +33,15 @@ func TableRowCount(ctx context.Context, dbConn *sqlx.DB, table string) (int64, e
if err := ValidateTableName(table); err != nil {
return 0, err
}
start := time.Now()
slog.Debug("db row count start", "table", table)
var count int64
query := fmt.Sprintf(`SELECT COUNT(*) FROM %s`, table)
if err := getLog(ctx, dbConn, &count, query); err != nil {
slog.Debug("db row count failed", "table", table, "duration", time.Since(start), "error", err)
return 0, err
}
slog.Debug("db row count complete", "table", table, "rows", count, "duration", time.Since(start))
return count, nil
}
@@ -422,10 +426,17 @@ func CheckpointSQLite(ctx context.Context, dbConn *sqlx.DB) error {
if ctx == nil {
ctx = context.Background()
}
start := time.Now()
slog.Debug("sqlite checkpoint start")
cctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
_, err := dbConn.ExecContext(cctx, `PRAGMA wal_checkpoint(TRUNCATE);`)
return err
if err != nil {
slog.Warn("sqlite checkpoint failed", "error", err, "duration", time.Since(start))
return err
}
slog.Debug("sqlite checkpoint complete", "duration", time.Since(start))
return nil
}
// EnsureVmHourlyStats creates the shared per-snapshot cache table used by Go aggregations.
@@ -1311,9 +1322,13 @@ func AnalyzeTableIfPostgres(ctx context.Context, dbConn *sqlx.DB, tableName stri
if driver != "pgx" && driver != "postgres" {
return
}
start := time.Now()
slog.Debug("db analyze start", "table", tableName)
if _, err := execLog(ctx, dbConn, fmt.Sprintf(`ANALYZE %s`, tableName)); err != nil {
slog.Warn("failed to ANALYZE table", "table", tableName, "error", err)
return
}
slog.Debug("db analyze complete", "table", tableName, "duration", time.Since(start))
}
// SetPostgresWorkMem sets a per-session work_mem for heavy aggregations; no-op for other drivers.