resumabble pg-fill
parent
633128e5c0
commit
47be0a513a
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue