Обсуждение: vacuuming taking long time for pg_attribute

Поиск
Список
Период
Сортировка

vacuuming taking long time for pg_attribute

От
Siraj G
Дата:
Hello Experts!

The PgSQL version is 16 and it runs in Cloud SQL managed by GCP.

Problem was that we were unable to conveniently get the object details in the schema browser (within the Cloud SQL Studio) as it was getting timeout again and again. Several application jobs start to fail. Eventually we found that pg_catalog.pg_attribute was having tons of dead tuples. While vacuum on this took several hours, the problem got resolved eventually.
Command ran: vacuum pg_attribute;

I would like to understand how this issue can be prevented. We do have autovacuum ON and I could see the last vacuum on this table was just about 30hrs back. 

Appreciate any suggestions.

Regards
Siraj

Re: vacuuming taking long time for pg_attribute

От
Siraj G
Дата:
One other thing I would like to add..
While the performance was problem, our application jobs also failed and we were unable to start them as internally they query pg_attribute.

Regards
Siraj

On Fri, Jan 17, 2025 at 11:45 AM Siraj G <tosiraj.g@gmail.com> wrote:
Hello Experts!

The PgSQL version is 16 and it runs in Cloud SQL managed by GCP.

Problem was that we were unable to conveniently get the object details in the schema browser (within the Cloud SQL Studio) as it was getting timeout again and again. Several application jobs start to fail. Eventually we found that pg_catalog.pg_attribute was having tons of dead tuples. While vacuum on this took several hours, the problem got resolved eventually.
Command ran: vacuum pg_attribute;

I would like to understand how this issue can be prevented. We do have autovacuum ON and I could see the last vacuum on this table was just about 30hrs back. 

Appreciate any suggestions.

Regards
Siraj

Re: vacuuming taking long time for pg_attribute

От
Laurenz Albe
Дата:
On Fri, 2025-01-17 at 11:45 +0530, Siraj G wrote:
> The PgSQL version is 16 and it runs in Cloud SQL managed by GCP.
>
> Problem was that we were unable to conveniently get the object details in the
> schema browser (within the Cloud SQL Studio) as it was getting timeout again
> and again. Several application jobs start to fail. Eventually we found that
> pg_catalog.pg_attribute was having tons of dead tuples. While vacuum on this
> took several hours, the problem got resolved eventually.
> Command ran: vacuum pg_attribute;
>
> I would like to understand how this issue can be prevented. We do have
> autovacuum ON and I could see the last vacuum on this table was just about
> 30hrs back. 
>
> Appreciate any suggestions.

I can only guess, but my guess is that you are creating temporary tables
very frequently.  Creating a temporary table insers the columns into
"pg_attribute", and they get deleted again when the session ends.

Perhaps autovacuum was just not fast enough, perhaps there were
long-running transactions or queries that prevented autovacuum from cleaning
up the dead rows in "pg_attribute".

Make sure your transactions are short and that autovacuum is configured
sufficiently aggressive.

Yours,
Laurenz Albe



Re: vacuuming taking long time for pg_attribute

От
Jeff Janes
Дата:
On Fri, Jan 17, 2025 at 1:15 AM Siraj G <tosiraj.g@gmail.com> wrote:
Hello Experts!

The PgSQL version is 16 and it runs in Cloud SQL managed by GCP.

Problem was that we were unable to conveniently get the object details in the schema browser (within the Cloud SQL Studio) as it was getting timeout again and again. Several application jobs start to fail. Eventually we found that pg_catalog.pg_attribute was having tons of dead tuples. While vacuum on this took several hours, the problem got resolved eventually.
Command ran: vacuum pg_attribute;

I would like to understand how this issue can be prevented. We do have autovacuum ON and I could see the last vacuum on this table was just about 30hrs back.

It might be hard to figure it out now that the evidence has likely been destroyed.  When looking at when the last autovac finished, did you also happen to capture the other column values in pg_stat_sys_tables for that relname?

Look in the db server log file to see if there were failed or canceled autovacuum attempts on that table.

I would probably set log_autovacuum_min_duration to a smallish value so that if it happens again you have some evidence to look at.

Cheers,

Jeff