From 47be0a513ade06a114a905789071a896f25615a0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:09:56 -0700 Subject: [PATCH] resumabble pg-fill --- cmd/pg-fill/main.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/pg-fill/main.go b/cmd/pg-fill/main.go index 14f5814..a9a20b8 100644 --- a/cmd/pg-fill/main.go +++ b/cmd/pg-fill/main.go @@ -29,15 +29,17 @@ func run(ctx context.Context) error { } return with.PSQL(ctx, *c, func(pg *sql.DB) error { - report := func() error { - var n2 uint64 + presently := func() int { + var n2 int if row := pg.QueryRowContext(ctx, `SELECT pg_total_relation_size('fill_with_data')/1024/1024`); row.Err() != nil { - return row.Err() + return 0 } else if err := row.Scan(&n2); err != nil { - return err + return 0 } - log.Printf("filled %vMiB of requested %vMiB", n2, *n) - return nil + return n2 + } + report := func() { + log.Printf("filled %vMiB of requested %vMiB", presently(), *n) } go with.Every(ctx, 5*time.Second, func() { @@ -53,7 +55,7 @@ func run(ctx context.Context) error { // https://gist.github.com/ololobus/5b25c432f208d7eb31051a5f238dffff // 2e6=1GB, so 2e6/8=12MB - for i := 0; i < (*n)/12; i++ { + for i := presently(); i < (*n)/12; i++ { for ctx.Err() == nil { if _, err := pg.ExecContext(ctx, ` INSERT INTO fill_with_data (x, y, z) @@ -72,6 +74,7 @@ func run(ctx context.Context) error { } } - return report() + report() + return nil }) }