Re: [PATCH] Periodically refresh database frozen IDs during autovacuum

From: Andres Freund <andres(at)anarazel(dot)de>
To: Jingtang Zhang <mrdrivingduck(at)gmail(dot)com>
Cc: pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Subject: Re: [PATCH] Periodically refresh database frozen IDs during autovacuum
Date: 2026-11-02 17:39:36
Message-ID: qxuq4rzul7sm3wuzsuo6i3ageo36twraucenusrfdiwzjboxne@igohofmvqlfn
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2026-11-03 00:40:15 +0800, Jingtang Zhang wrote:
> This patch periodically refreshes the database's frozen-ID horizons
> between tables. A shared per-database completion timestamp controls
> periodic attempts at a fixed interval, currently set to ten minutes.
> This is a tentative value for discussion, since more frequent updates
> incur additional scanning overhead. I have not yet decided whether to
> make the interval configurable via a GUC.
>
> To prevent multiple workers from refreshing the same database
> concurrently, periodic updates acquire the database frozen-ID lock
> conditionally. If the lock is already held, another backend is handling
> the database-level refresh, so the worker skips its attempt and
> continues processing tables. The existing final blocking refresh is
> retained as a fallback.

I think theres some responsibilities that aren't quite right here (even before
your change). A few comments (both about the current state and the patch):

- Just updating the datfrozenxid at the end of an autovacuum and a
multi-relation vacuum is problematic and makes it more likely that
anti-wraparound measures are hit

I think the same update-more-often logic needs to be done for multi-relation
vacuums.

- Calling vac_update_datfrozenxid() unconditionally in do_autovacuum(), even
though relfrozenxid wasn't updated, is wasteful and makes more frequent
calls problematic

The justification for calling vac_update_datfrozenxid() even if we didn't
vacuum anything doesn't mean we can't push the responsibility for other
calls to vac_update_datfrozenxid() down. If we do, we can make those
updates conditional.

- We shouldn't block waiting for LockDatabaseFrozenIds in most cases, because
that means somebody else is already doing the work.

I suspect we should use something like the ForceTransactionIdLimitUpdate()
check at the end of vac_update_datfrozenxid() to determine whether to block
or not.

That seems like something independent of more frequently updating
datfrozenxid. So it probably should be a separate patch.

- The timing logic the patch introduces makes calls to
vac_update_datfrozenxid() independent of relfrozenxid having been updated,
that

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-11-02 17:39:40 Re: [PATCH] Fix segmentation fault caused by reentrancy in RI_Fkey_cascade_del (ri_triggers.c)
Previous Message Greg Burd 2026-11-02 17:18:22 Re: [PATCH] Corruption Issue: Fix missing tts_tid in ExecForceStoreHeapTuple