mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-09 10:57:08 +02:00
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:
parent
8eb9205dc8
commit
184c4ad040
1 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue