Skip to content

Commit 9ec6e12

Browse files
committed
fix: report worker activity to pg_stat_activity
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.
1 parent feaef76 commit 9ec6e12

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/worker.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ void pg_net_worker(__attribute__((unused)) Datum main_arg) {
265265

266266
publish_state(WS_RUNNING);
267267

268+
// Initial state: we go straight into the outer loop and wait for a wake.
269+
pgstat_report_activity(STATE_IDLE, NULL);
270+
268271
do {
269272

270273
uint32 expected = 1;
@@ -274,6 +277,8 @@ void pg_net_worker(__attribute__((unused)) Datum main_arg) {
274277
continue;
275278
}
276279

280+
pgstat_report_activity(STATE_RUNNING, NULL);
281+
277282
uint64 requests_consumed = 0;
278283
uint64 expired_responses = 0;
279284

@@ -388,6 +393,9 @@ void pg_net_worker(__attribute__((unused)) Datum main_arg) {
388393

389394
} while (!worker_should_restart && (requests_consumed > 0 || expired_responses > 0));
390395

396+
// Inner loop drained; back to waiting for the next wake.
397+
pgstat_report_activity(STATE_IDLE, NULL);
398+
391399
} while (!worker_should_restart);
392400

393401
publish_state(WS_EXITED);

0 commit comments

Comments
 (0)