feat(schema): insert-driven autovacuum storage parameters - #165
Open
arreyder wants to merge 1 commit into
Open
Conversation
arreyder
force-pushed
the
crr/autovacuum-insert-threshold
branch
2 times, most recently
from
August 21, 2026 02:47
c09152c to
7ef6c41
Compare
Adds autovacuum_vacuum_insert_threshold and autovacuum_vacuum_insert_scale_factor (PG13+) to StorageParameters. The existing autovacuum_vacuum_threshold / autovacuum_vacuum_scale_factor pair triggers on DEAD tuples. On an append-mostly table that pair may rarely fire however tightly it is set: dead tuples accumulate slowly relative to inserts while freshly-inserted pages pile up all-visible but unmarked. The stale visibility map is what makes an Index Only Scan fall back to heap fetches. The insert-driven pair triggers on inserts since the last vacuum, which is what refreshes the visibility map -- the gap PostgreSQL added these for. Both render paths are covered: storageParams2with (CREATE) and storageParams2alterTable (drift-detection ALTER), so the retrofit machinery applies these to existing tables -- which is the case that matters, since a table large enough to need this is not one anybody recreates. The generator's storage-parameter plumbing is a hand-maintained mirror of the proto message (storageParamsTemplateContext, its extraction block, and descriptor.tmpl all enumerate parameters one by one). A parameter added only to the .proto and the SQL renderers is silently dropped before it ever reaches GetStorageParameters(), and if a message declared only such parameters, hasStorageParams would stay false and the whole storage_parameters block would emit `return nil`. All three sites are updated here, and the new example declaration on Pet plus its assertions in TestPetStorageParameters cover that declaration-to-descriptor path so the next parameter added cannot regress it silently. That also gets the reloption names validated against a real server by the existing PostgreSQL-backed animals suite. needsUpdate's float comparison used a fixed absolute epsilon of 1e-4. The scale factors worth setting on a large append-mostly table sit at or below that, so drift was reported as agreement and never converged. It is now relative (1e-9 + 1e-4 * |desired|), which still absorbs float32 round-trip noise -- the existing precision-difference case is unchanged. int32 for the threshold, matching the sibling autovacuum_vacuum_threshold and PostgreSQL's 32-bit reloption. Generated with protoc-gen-go v1.36.11, the version main was generated with, so the diff carries no spurious toolchain bump.
arreyder
force-pushed
the
crr/autovacuum-insert-threshold
branch
from
August 21, 2026 02:48
7ef6c41 to
ad18c7f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
autovacuum_vacuum_insert_thresholdandautovacuum_vacuum_insert_scale_factor(PG13+) toStorageParameters, fields 13 and 14.Why the existing pair doesn't cover this
autovacuum_vacuum_threshold/autovacuum_vacuum_scale_factortrigger on dead tuples. On an append-mostly table that means they may rarely fire however tightly they are set: dead tuples accumulate slowly relative to inserts, while freshly-inserted pages pile up all-visible-but-unmarked. That stale visibility map is what makes an Index Only Scan fall back to heap fetches, which surfaces as a poor buffer-cache hit ratio on a scan that ought to be cheap.The insert-driven pair triggers on inserts since the last vacuum, which is what refreshes the visibility map. PostgreSQL added them for exactly this gap. On a large append-mostly table the dead-tuple trigger is the wrong knob for that symptom, and tightening it further does not become the right one.
The generator plumbing is a hand-maintained mirror — worth knowing about
The storage-parameter path is enumerated parameter-by-parameter in three places:
storageParamsTemplateContext, its extraction block ininternal/pgdb/pgdb_descriptor.go, andinternal/pgdb/templates/descriptor.tmpl. A parameter added only to the.protoand to the SQL renderers is silently dropped before it reachesGetStorageParameters()— and if a message declared only such parameters,hasStorageParamsstaysfalseand the whole block emitsreturn nil.All three sites are updated here. To stop that being re-discovered the hard way,
Petin the example models now declares both parameters andTestPetStorageParametersasserts they survive codegen — the only test in the repo covering declaration → generated descriptor. That also gets the reloption names validated against a real server for free by the existing PostgreSQL-backed animals suite, which is the one thing no unit test can do.Drift detection: relative epsilon
needsUpdatecompared floats with a fixed absolute epsilon of1e-4. The scale factors worth setting on a large append-mostly table sit at or below that, so e.g. declared0.001against an existing0.0011(10% off) compared equal — drift was reported as agreement and never converged. It's now relative (1e-9 + 1e-4 * |desired|), which still absorbsfloat32round-trip noise; the existing precision-difference case is unchanged, and there are now cases on both sides of that boundary.Coverage
Both render paths —
storageParams2with(CREATE) andstorageParams2alterTable(drift-detection ALTER), so the retrofit machinery applies these to existing tables, which is the case that matters since a table big enough to need this is not one anybody recreates. Cases cover: each of the pair set alone (a guard checking the sibling's presence would pass the both-set case), the pair alongside other parameters,-1(PostgreSQL's documented sentinel for disabling the trigger), both-drifted and one-drifted retrofit, and small-scale-factor drift vs. round-trip noise.Notes for the reviewer
int32for the threshold, matching the siblingautovacuum_vacuum_thresholdand PostgreSQL's 32-bit reloption.mainwas generated with, so the diff carries no spurious toolchain bump. Verified codegen reproducesmainbyte-for-byte before applying the change../pgdb/...and./example/models/{animals,zoo}/...pass. Five tests inexample/models/food/v1fail in my environment onERROR: extension "vector" is not available— no pgvector locally; they fail identically on cleanmain, verified by stashing.crr/add-storage-parametersreserves field 13 fordefault_statistics_target. Nothing onmainoccupies 13/14, but whichever lands second needs renumbering.