Re: Track skipped tables during autovacuum and autoanalyze - Mailing list pgsql-hackers

From Yugo Nagata
Subject Re: Track skipped tables during autovacuum and autoanalyze
Date
Msg-id 20260326192203.e6dbb8d80f8d27dc15ceee59@sraoss.co.jp
Whole thread Raw
In response to Re: Track skipped tables during autovacuum and autoanalyze  (Yugo Nagata <nagata@sraoss.co.jp>)
Responses Re: Track skipped tables during autovacuum and autoanalyze
List pgsql-hackers
> On Tue, 24 Mar 2026 09:58:48 -0500
> Sami Imseih <samimseih@gmail.com> wrote:

> > 1/
> > 
> > +                       if (AmAutoVacuumWorkerProcess())
> > +                               pgstat_report_skipped_vacuum(relid);
> > 
> > Any reason why this should not also include manual vacuum/analyze?
> > If someone has a vacuum/analyze script that uses SKIP_LOCKED, and
> > the operation gets skipped, this should be included in the counter.
> > this can be done with separate counter fields for autovacuum/autoanalyze and
> > vacuum/analyze
> 
> For manual vacuum/analyze, an explicit WARNING is output when the
> operation is skipped, so I initially thought that reporting it in the
> stats view was not necessary. However, I now agree that it should be
> included.

I've attached an updated patch to also report skipped manual
vacuum/analyze.

The pgstat reporting functions are unified into a single function,
pgstat_report_skipped_vacuum_analyze(), which handles both
auto/manual and vacuum/analyze cases. Also it is fixed to use
InvalidOid for shared relations.

To support manual vacuum/analyze, some hack were needed to
obtain the relid before the lock attempt. When SKIP_LOCKED is specified,
the relid is obtained using RangeVarGetRelid() with NoLock prior to
locking. If ConditionalLockRelationOid() then fails, the skip is
reported.

To handle the possibility that the table is dropped between
RangeVarGetRelid() and the lock attempt, SearchSysCacheExists1() is
used after acquiring the lock.

Regards,
Yugo Nagata

-- 
Yugo Nagata <nagata@sraoss.co.jp>

Attachment

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Better shared data structure management and resizable shared data structures
Next
From: Nisha Moond
Date:
Subject: Re: Use SIGTERM instead of SIGUSR1 for slotsync worker to exit during promotion?