Skip to content

fix: skip autovacuum metric when xact_start is NULL - #1381

Open
locker95 wants to merge 1 commit into
prometheus-community:masterfrom
locker95:fix-autovacuum-null-xact-start
Open

fix: skip autovacuum metric when xact_start is NULL#1381
locker95 wants to merge 1 commit into
prometheus-community:masterfrom
locker95:fix-autovacuum-null-xact-start

Conversation

@locker95

@locker95 locker95 commented Sep 1, 2026

Copy link
Copy Markdown

The stat_activity_autovacuum collector scans EXTRACT(EPOCH FROM xact_start) into a plain float64. xact_start can be NULL for autovacuum workers, and when that happens the Scan fails with converting NULL to float64 is unsupported and the entire collector errors out, as reported in #952.

This changes the scan target to sql.NullFloat64 and skips the row when the value is NULL, following the same pattern the pg_stat_walreceiver and pg_stat_database collectors use. Skipping rather than reporting 0 matches sysadmind's comment on the issue: "The typical options are to report a 0 value or to skip the metric all together. I usually lean towards the latter." Rows with a valid timestamp keep being emitted as before.

The regression test adds a NULL-timestamp row mixed with a normal row; it reproduces the exact Scan error before the fix and verifies the NULL row is skipped and the valid row still emitted after.

Fixes #952

The stat_activity_autovacuum collector scanned xact_start into a plain
float64, so a NULL value (possible for autovacuum workers) failed the
whole collector with "converting NULL to float64 is unsupported". Scan
into sql.NullFloat64 and skip the row when it is NULL, matching the
pg_stat_walreceiver / pg_stat_database collectors.

Fixes prometheus-community#952

Signed-off-by: Dean Chen <862469039@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stat_activity_autovacuum: timestamp_seconds can be NULL?

1 participant