Question on adl_next_worker condition in autovacuum launcher

From: Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
To: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Question on adl_next_worker condition in autovacuum launcher
Date: 2025-08-01 16:15:02
Message-ID: 20250802011502.1485eedaf998b4bd24dc270b@sraoss.co.jp
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

With regard to my previous post [1], I have a question about the
autovacuum launcher codes.

In do_start_worker(), the following conditions determins whether a database
should be skipped or not.

/*
* Skip this database if its next_worker value falls between
* the current time and the current time plus naptime.
*/
if (!TimestampDifferenceExceeds(dbp->adl_next_worker,
current_time, 0) &&
!TimestampDifferenceExceeds(current_time,
dbp->adl_next_worker,
autovacuum_naptime * 1000))
skipit = true;

This means a database is skipped when
current_time < adl_next_woker < current_time + autovacuum_naptime.

However, I don't quite understand why ther upper bound condition is necessary.
After a database has been processed, adl_next_woker is set in launch_worker() as follows:

/*
* add autovacuum_naptime seconds to the current time, and use
* that as the new "next_worker" field for this database.
*/
avdb->adl_next_worker =
TimestampTzPlusMilliseconds(now, autovacuum_naptime * 1000);

Here "now < current_time (in do_start_worker())", so I believe
"adl_next_woker < current_time + autovacuum_naptime"
will always be true. Therefore, it seems redundant to explicitly check the upper bound.

Am I missing something? I’d appreciate it if anyone could clarify this for me.

[1] https://www.postgresql.org/message-id/20250802002027.cd35c481f6c6bae7ca2a3e26%40sraoss.co.jp

Regards,
Yugo Nagata
--
Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2025-08-01 16:58:34 Re: Add support for specifying tables in pg_createsubscriber.
Previous Message Heikki Linnakangas 2025-08-01 16:12:10 Re: BackendKeyData is mandatory?