Re: Vacuum Analyze

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Michael Wallach <twodown02(at)gmail(dot)com>, pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Re: Vacuum Analyze
Date: 2024-06-29 04:49:30
Message-ID: de12423767d97ec942459d53f41604578fb48070.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, 2024-06-28 at 17:09 -0400, Michael Wallach wrote:
> Having issue with DB where we see SQL get slow, not sure what is causing but
> queries that have been running sub second jump to 2-5 secs. Seems when we manually
> run VACUUM ANALYZE query perf immediately improves. To add to this we have a “job”
> to trigger VACUUM ANALYZE to run every day but despite this, some acton against DB
> results in performance regarding that is only fixed by again running VACUUM ANALYZE.
>
> What I’m trying to understand is what should I be looking at as before/after in the
> tables to determine what exactly VACUUM ANALYZE might be affecting to identify cause,
> what is corrected in DB such that perf improves? The DB is being exercised by custom
> apps via API so not sure what is happening that is causing DB to quickly become
> non-performant?

You'd have to investigate that more closely.

The key tool is EXPLAIN (ANALYZE, BUFFERS) SELECT ...

Do that when the query is fast and then again later when the query is slow.

The output tells you what exactly the database is doing to execute the query,
and it also tells you what parts are slow in the second case. Once you understand
the cause of the problem, you can usually address it in a much more precise fashion.

VACUUM (ANALYZE) on the whole database is a pretty big hammer. Perhaps all that
is necessary is to tune autovacuum to ANALYZE or VACUUM a certain table more often.

Yours,
Laurenz Albe

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Brian McMahon 2024-07-30 15:53:55 Support for on conflict ignore returning
Previous Message Michael Wallach 2024-06-28 21:09:57 Vacuum Analyze