Re: Aggressive vacuum

From: Slava Mudry <slava44(at)gmail(dot)com>
To: Graham Hay <grahamrhay(at)gmail(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Aggressive vacuum
Date: 2025-01-06 23:18:28
Message-ID: CAEFxPe0Rf798WEer6P+QU78sGB87cxUQ03SHjmx6FW_mP72msg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello Graham,
I had to deal with "vacuum to prevent wraparound" a few times and it's not
fun :(
Postgres doc explains it very well.. if you see that nasty thing running on
your db, your best options are:
1. manually vacuum freeze the table
2. examine vacuum costs and lower them to make sure the autovacuum can do
it's job. Allow more vacuum processes by tuning *autovacuum_max_workers*
3. tune and set autovacuum settings for your table to make sure autovacuum
picks it up sooner than defaults allow it so.

Depending on your usage, there are some other good optimizations you can
try.. The best in my opinion is to partition the large table and isolate
old rows from frequently updated rows and manually vacuum freeze rows that
you know wan't change. Also newer postgres versions have improved the
autovacuuming, if you're on ver 15 (based on your link to docs), you should
consider upgrading to more recent version.
Good luck,
-Slava

On Thu, Dec 19, 2024 at 5:37 AM Graham Hay <grahamrhay(at)gmail(dot)com> wrote:

> Can anyone enlighten me on exactly what triggers an "aggressive"
> vacuum? I have read the docs multiple times (and watched several
> videos!), but the changes I make do not have the expected outcomes; so
> I'm clearly missing something.
>
>
> https://www.postgresql.org/docs/15/routine-vacuuming.html#VACUUM-FOR-WRAPAROUND
>
> I have a fairly large table, that has outgrown the vacuum defaults. We
> started by setting:
>
> - autovacuum_vacuum_scale_factor=0
> - autovacuum_vacuum_threshold=100000 # 100K
>
> (10% was a lot of tuples). This was definitely an improvement, but
> when the big vacuum (freeze) kicked off there was a noticeable
> io/latency spike. We then tried setting:
>
> - autovacuum_freeze_table_age=100000000 # 100M
>
> which seemed to make it happen more frequently (and one would hope,
> with less work to do). We reduced this to 50M, and again it was more
> frequent (but not the 2x I expected). And when I dropped it to 10M,
> nothing changed.
>
> After re-reading the docs, I got the impression I also needed to set:
>
> - autovacuum_freeze_min_age=10000000 # 10M
>
> As the system default was 50M. And again, this had an effect, but not
> the 5x I was expecting. The docs say:
>
> > all-visible but not all-frozen pages are scanned if the number of
> transactions that have passed since the last such scan is greater than
> vacuum_freeze_table_age minus vacuum_freeze_min_age
>
> but wouldn't that have been 10M - 50M? i.e. -40M. Is there some other
> setting I'm missing?
>
> All suggestions welcome!
>
> Thanks,
>
> Graham
>
>
>

--
-slava

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message jian he 2025-01-07 09:07:22 Re: Re: proposal: schema variables
Previous Message Pavel Stehule 2025-01-06 19:10:12 Re: Re: proposal: schema variables