fix: flush pgstat counters from worker so autovacuum sees its writes#254
Merged
Conversation
Background workers performing DML via SPI must call pgstat_report_stat() themselves; regular user backends get this for free via tcop/postgres.c's main loop. Without it, per-write counters (n_tup_ins, n_tup_del, n_mod_since_analyze) for the worker's writes to net._http_response and net.http_request_queue never reach shared stats. Autovacuum/autoanalyze never see anything to vacuum, and net._http_response (written only by the worker) silently bloats - eventually surfacing as 20-100s expiry DELETEs on a bloated `created` index.
za-arthur
approved these changes
May 18, 2026
za-arthur
left a comment
There was a problem hiding this comment.
Good catch! LGTM. I have just a suggestion below.
This was referenced May 18, 2026
Merged
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Auto vacuum/analyze will not trigger on the
net._http_responseFix
Call
pgstat_report_stat(false)after each worker transaction commits. Perpgstat.c:Regular user backends invoke it from the main loop after each query; background workers have no equivalent and must flush themselves.
Tests
Two regression tests added to
test/test_worker_behavior.py:test_worker_writes_increment_pgstat_counters— drives 30 requests through the worker and assertspg_stat_user_tables.n_tup_ins > 0onnet._http_response. Before the fix, this stays at 0; with the fix, it reflects the worker's INSERTs.test_worker_writes_trigger_autoanalyze_on_http_response— end-to-end test that proves the customer-impacting symptom is resolved. Configuresautovacuum_naptime=1splus low per-table thresholds, drives traffic, and waits forautoanalyze_count > 0.Linear: https://linear.app/supabase/issue/PSQL-1216