Skip to content

Commit 976a417

Browse files
AlexeyShalaevAlexey Shalaev
andauthored
docs: what --batch-rows bounds during a backfill, measured (#91)
The CLI guide said --batch-rows bounds how long a window's rows are out of sight. It is the other way round: batches commit on their own, so a window is out of sight for as long as its whole move takes, and larger batches shorten that. Smaller batches keep each statement short. Both guides now say so, with the numbers measured on Outpost's schema, and recommend running apply once before the first backfill. Co-authored-by: Alexey Shalaev <shalaevad.alexey@gmail.com>
1 parent e11f959 commit 976a417

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎docs/guide/cli.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,22 @@ until pg-partsmith backfill -c partitions.yaml --max-batches 50; do sleep 60; do
330330

331331
Two things to know before running it on a busy table. It takes the table's maintenance
332332
lock for the duration of each call, so a scheduled `apply` will decline while it runs
333-
(exit `6`), which is the lock doing its job. And a window's rows are invisible through
334-
the parent between the moment they leave DEFAULT and the moment the partition is attached
335-
— PostgreSQL will not attach a partition while DEFAULT still holds rows for it, so there
336-
is no order that keeps them visible throughout. `--batch-rows` bounds how long that is.
333+
(exit `6`), which is the lock doing its job. And a window's rows are out of sight through
334+
the parent from the moment its first batch commits until the partition is attached —
335+
PostgreSQL will not attach a partition while DEFAULT still holds rows for it, so there is
336+
no order that keeps them visible throughout.
337+
338+
Each batch commits on its own, so that gap is the time the whole window takes to move:
339+
fewer, larger batches shorten it, and a batch at least as large as the window leaves only
340+
the attach. What smaller batches keep short is each statement, and with it how long DEFAULT
341+
is held and how much one transaction writes. Run `apply` once before the first `backfill`:
342+
the current month is then attached, and new rows stop landing in DEFAULT behind the batches.
343+
344+
Measured on Outpost's schema (PostgreSQL 17, 300,000 rows per table in DEFAULT, a writer
345+
inserting 20 rows a second into the current month, `apply` first): with the default 10,000
346+
rows per batch a month's rows were out of sight for up to 0.42 s and inserts waited at most
347+
128 ms; with batches larger than a month, out of sight for about 30 ms, and inserts waited
348+
up to 247 ms.
337349

338350
## Commands around the lifecycle
339351

‎docs/guide/partition-existing-table.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ readers see them and the next call takes the window again.
9090
While a window's rows are being moved, they sit in a partition that is not yet
9191
attached and are **invisible through the parent**. PostgreSQL leaves no other order —
9292
a partition cannot be attached while DEFAULT still holds rows for it. Run the drain in
93-
a maintenance window, or with small batches during a quiet hour and readers that can
94-
tolerate a month's rows appearing a little later. Rows already in real partitions, and
93+
a maintenance window, or during a quiet hour with readers that can tolerate a month's
94+
rows appearing a little later. The gap runs from the window's first batch to its
95+
attach, so larger batches shorten it ([measured](cli.md#adopting-a-table-full-of-data)).
96+
Rows already in real partitions, and
9597
rows still in DEFAULT for other windows, stay visible throughout. The attach that ends
9698
a window blocks writers at the parent and holds `ACCESS EXCLUSIVE` on the DEFAULT
9799
partition, for the length of the last batch's tail plus one scan of DEFAULT — so

0 commit comments

Comments
 (0)