Re: Disabling vacuum truncate for autovacuum

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Gurjeet Singh <gurjeet(at)singh(dot)im>, Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>, Will Storey <will(at)summercat(dot)com>
Subject: Re: Disabling vacuum truncate for autovacuum
Date: 2025-02-28 03:35:51
Message-ID: Z8EvFyf1D1AMxjOg@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Feb 18, 2025 at 01:56:09PM -0600, Nathan Bossart wrote:
> On Mon, Jan 27, 2025 at 03:38:39PM -0500, Robert Haas wrote:
>> Also, how sure are we that turning this off globally is a solid idea?
>> Off-hand, it doesn't sound that bad: there are probably situations in
>> which autovacuum never truncates anything anyway just because the tail
>> blocks of the relations always contain at least 1 tuple. But we should
>> be careful not to add a setting that is far more likely to get people
>> into trouble than to get them out of it. It would be good to hear what
>> other people think about the risk vs. reward tradeoff in this case.
>
> My first reaction is that a global setting is probably fine most of the
> time. I'm sure it's possible to get into bad situations if you try hard
> enough, but that's not a unique characteristic. There are probably many
> situations where the truncation is wasted effort because we'll just end up
> extending the relation shortly afterwards, anyway. In any case, it's
> already possible to achieve $SUBJECT with a trivial script that sets
> storage parameters on all tables, so IMHO it would be silly to withhold a
> global setting that does the same thing just on principle.

I spent some time on this one today. A couple of notes:

* Since the reloption is a Boolean, there isn't a good way to tell whether
it is actually set for the table or if it just inherited the default
value. This is important to know because we want the reloption to
override the GUC. I considered a bunch of different ways to handle this,
but everything felt like a cowboy hack. The cleanest cowboy hack I could
come up with is an optional offset field in relopt_parse_elt that points
to a variable that stores whether the option was explicitly set.

* I didn't see a good GUC category for vacuum_truncate. I suppose we could
create a new one, but for now I've just stashed it into the autovacuum
one. Bikeshedding welcome.

Thoughts?

--
nathan

Attachment Content-Type Size
v2-0001-Add-vacuum_truncate-GUC.patch text/plain 9.7 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gurjeet Singh 2025-02-28 04:29:16 Re: Disabling vacuum truncate for autovacuum
Previous Message Adrian Klaver 2025-02-27 21:07:22 Re: How to debug: password authentication failed for user

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Sabino Mullane 2025-02-28 03:42:17 Re: Statistics Import and Export
Previous Message Amit Kapila 2025-02-28 03:26:40 Re: Restrict copying of invalidated replication slots