mxid_score can become Infinity in pg_stat_autovacuum_scores

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: mxid_score can become Infinity in pg_stat_autovacuum_scores
Date: 2026-06-12 18:19:31
Message-ID: CAD21AoC6nKeYAjTvJ9dmBea03GZK9222h_O=ONmcVuxfyO88Bg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

While testing the autovacuum score, I noticed that scores->mxid could
be infinity by the following calculation in
relation_needs_vacanalyze():

scores->mxid = (double) mxid_age / multixact_freeze_max_age;

The variable multixact_freeze_max_age originates from
effective_multixact_freeze_max_age, which is determined by
MultiXactMemberFreezeThreshold(). As noted in the comments for
MultiXactMemberFreezeThreshold(), it can return 0 under certain
conditions:

/* fraction could be > 1.0, but lowest possible freeze age is zero */
if (fraction >= 1.0)
return 0;

Since mxid_age is cast to a double before the division, this does not
trigger a division-by-zero error or cause a server crash. However,
scores->mxid results in 'inf', which displays as "Infinity" in the
mxid_score column of the pg_stat_autovacuum_scores view. While this
might not be intentional, it seems better to prevent mxid_score from
becoming infinity by doing something like this:

- scores->mxid = (double) mxid_age / multixact_freeze_max_age;
+ scores->mxid = (double) mxid_age / Max(multixact_freeze_max_age, 1);

Any thoughts on this?

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2026-06-12 18:58:52 Re: [PATCH] seg: preserve the upper boundary's certainty indicator in seg_out()
Previous Message Tom Lane 2026-06-12 18:01:50 Do quoting more carefully in replication commands