fix: report worker activity to pg_stat_activity#255
Merged
Conversation
Background workers must call pgstat_report_activity() themselves to update state/state_change in pg_stat_activity; regular user backends get this for free via tcop/postgres.c. Without it the pg_net worker shows up with a blank state column, making it impossible to tell from monitoring whether the worker is idle, processing a tick, or stuck in a transaction. Adds STATE_IDLE / STATE_RUNNING transitions around the inner work loop. cmd_str is NULL, matching what other background workers (e.g. logical replication apply worker) do; backend_type already identifies it as "pg_net <ver> worker" so a query-column label would be redundant.
Member
|
@utkarash2991 Can we test this somehow? |
Contributor
Author
@steve-chavez Added a regression test in 8ec2990. It asserts pg_stat_activity.state shows 'idle' at rest and 'active' during a slow request (using delay=2 so the active window is observable). Please let me know how this looks . |
Contributor
Author
@steve-chavez does the changes looks good to you ? ok to merge ? |
This was referenced May 19, 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.
Problem
The pg_net background worker doesn't call
pgstat_report_activity(), so its row inpg_stat_activityshows up with blankstate,query,query_start,xact_start, andstate_changecolumns. This makes it impossible to tell from monitoring whether the worker is idle, processing a tick, or stuck in a transaction.Regular user backends get this for free via
tcop/postgres.c. Background workers must do it themselves.Fix
Add
pgstat_report_activitytransitions around the inner work loop:STATE_IDLEinitially (worker starts by waiting for a wake)STATE_RUNNINGwhen the worker enters the inner work loopSTATE_IDLEwhen the inner loop drains and the worker goes back to waitingcmd_str = NULL, matching what other background workers do (logical replication apply worker, walsender on idle).backend_typealready identifies the row as"pg_net <ver> worker", so a query-column label would be redundant.Verification
Sample output before/after on a local repro:
Before (
backend_type ilike '%pg_net%'):After, at rest:
After, while processing a tick:
Refs PSQL-1221, follow-up to #254.