Possible to trigger autovacuum?

Started by Chris Clevelandalmost 2 years ago3 messages
#1Chris Cleveland
ccleveland@dieselpoint.com

Is it possible to launch an autovacuum from within an extension?

I'm developing an index access method. After the index gets built it needs
some cleanup and optimization. I'd prefer to do this in the
amvacuumcleanup() method so it can happen periodically and asynchronously.

I could fire up a background worker to do the job, but it would be a lot
simpler to call please_launch_autovacuum_right_now();

--
Chris Cleveland
312-339-2677 mobile

#2Michael Paquier
michael@paquier.xyz
In reply to: Chris Cleveland (#1)
Re: Possible to trigger autovacuum?

On Mon, Feb 19, 2024 at 03:15:29PM -0600, Chris Cleveland wrote:

Is it possible to launch an autovacuum from within an extension?

I'm developing an index access method. After the index gets built it needs
some cleanup and optimization. I'd prefer to do this in the
amvacuumcleanup() method so it can happen periodically and asynchronously.

I could fire up a background worker to do the job, but it would be a lot
simpler to call please_launch_autovacuum_right_now();

The autovacuum launcher can be stopped in its nap with signals, like a
SIGHUP. So you could rely on that to force a job to happen on a given
database based on the timing you're aiming for.
--
Michael

#3Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Chris Cleveland (#1)
Re: Possible to trigger autovacuum?

On 2024-Feb-19, Chris Cleveland wrote:

Is it possible to launch an autovacuum from within an extension?

I'm developing an index access method. After the index gets built it
needs some cleanup and optimization. I'd prefer to do this in the
amvacuumcleanup() method so it can happen periodically and
asynchronously.

Autovacuum has a mechanism to be requested work -- grep the tree for
AutoVacuumRequestWork and AutoVacuumWorkItemType. Currently its only
use is BRIN autosummarization, but it's possible to add others by
patching the core code. If you want to propose the idea of making it
extensible, I think it would serve not only your present use case but
plenty of others, too.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/