Re: Index not getting cleaned even though vacuum is running

From: Matheus Alcantara <mths(dot)dev(at)pm(dot)me>
To: "Karthik Jagadish (kjagadis)" <kjagadis(at)cisco(dot)com>
Cc: "pgsql-user(at)postgresql(dot)org" <pgsql-user(at)postgresql(dot)org>, "Prasanna Satyanarayanan (prassaty)" <prassaty(at)cisco(dot)com>, "Chandruganth Ayyavoo Selvam (chaayyav)" <chaayyav(at)cisco(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Index not getting cleaned even though vacuum is running
Date: 2022-11-16 22:29:26
Message-ID: FiAZlayN-OjAIW3P4yCjDHQLOW3lMethetIWnP2VTUbqCgM7nYTrz3kKPL9ZB7urikaEvvtEpEQR995FfVeVoNqTvbpuuMjqhbKueHrrFeQ=@pm.me
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

------- Original Message -------
On Tuesday, November 15th, 2022 at 12:38, Karthik Jagadish (kjagadis) <kjagadis(at)cisco(dot)com> wrote:

> Hi,
>
> We notice that vacuum is happening at regular intervals but the space occupied by indexes is always increasing. Any pointers as to why would this happen?
>
> Some outputs below. Auto vacuum is enabled but we notice index size is growing.
>
> $ psql -U postgres -d cgms -c "SELECT pg_size_pretty(SUM(pg_relation_size(table_schema||'.'||table_name))) as size from information_schema.tables"
>
> size
>
> -------
>
> 25 GB
>
> (1 row)
>
> $ psql -U postgres -d cgms -c "SELECT pg_size_pretty(SUM(pg_indexes_size(table_schema||'.'||table_name) + pg_relation_size(table_schema||'.'||table_name))) as size from information_schema.tables"
>
>   size
>
> --------
>
> 151 GB
>
> (1 row)
>
> $ sudo du -hsc /var/lib/pgsql/12/data
>
> 154G    /var/lib/pgsql/12/data
>
> 154G    total
>
> Appreciate if someone can give some pointers.
>
> Regards,
>
> Karthik

As far as I know vacuum just mark the space of dead rows available for future
reuse, so I think it's expected that the size doesn't decrease.

"The standard form of VACUUM removes dead row versions in tables and indexes
and marks the space available for future reuse. However, it will not return the
space to the operating system, except in the special case where one or more
pages at the end of a table become entirely free and an exclusive table lock
can be easily obtained. In contrast, VACUUM FULL actively compacts tables by
writing a complete new version of the table file with no dead space. This
minimizes the size of the table, but can take a long time. It also requires
extra disk space for the new copy of the table, until the operation completes."

https://www.postgresql.org/docs/current/routine-vacuuming.html

--
Matheus Alcantara

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2022-11-16 22:31:57 Re: Suppressing useless wakeups in walreceiver
Previous Message Tom Lane 2022-11-16 22:26:03 Re: Allow single table VACUUM in transaction block