feat(pglite): checkpoint after ANALYZE at the end of a scan

PGlite's single-user backend has no background checkpointer, so nothing
written during a scan is checkpointed until shutdown, and a crash would
replay the whole scan's WAL. Run CHECKPOINT right after the post-scan
ANALYZE. The log directory itself stays around max_wal_size because
PostgreSQL recycles segments rather than deleting them.
This commit is contained in:
Deluan 2026-09-05 01:14:48 -04:00
commit 184c4ad040

View file

@ -141,6 +141,14 @@ func optimizeAt(ctx context.Context, db *sql.DB, now time.Time) error {
if err = recordAnalyzeSuccess(ctx, db, now); err != nil {
return recordAnalyzeError(ctx, db, now, err)
}
// The single-user backend has no checkpointer, so a scan's worth of WAL would only be
// checkpointed at shutdown; do it here so a crash never has to replay the whole scan.
start := time.Now()
if _, err := db.ExecContext(ctx, "CHECKPOINT"); err != nil {
log.Warn(ctx, "Error running CHECKPOINT", err)
} else {
log.Debug(ctx, "Checkpoint completed", "elapsed", time.Since(start))
}
return nil
}