From: Dimitrios Apostolou <jimis@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Moving data from huge table slow, min() query on indexed column taking 38s
Date: Fri, 21 Jul 2023 09:20:37 +0200 (CEST)
Message-ID: <68257d84-96e5-9dca-ff31-c9f45e356543@gmx.net> (raw)
In-Reply-To: <096aa4b3-892e-7fa5-7370-3a1895e7d6a0@gmx.net>
References: <096aa4b3-892e-7fa5-7370-3a1895e7d6a0@gmx.net>
On Thu, 6 Jul 2023, Dimitrios Apostolou wrote:
> + Then I broke the command above in many small chunks
>
> WITH rows AS (
> DELETE FROM tbl_legacy AS t
> WHERE (partition_key_column < $1)
> RETURNING t.*
> ) INSERT INTO tbl SELECT * FROM rows;
> COMMIT;
>
> I increase the parameter $1 and keep going in a loop. At first this
> goes OK, after one day though I notice that it has slowed down
> significantly. My investigation shows that the simple query
>
> SELECT min(partition_key_column) from tbl_legacy;
>
> takes 38s, despite having an index on the column! A VACUUM fixes that,
> so I guess the index has a ton of dead tuples. I guess autovacuum does
> not do its job because the table is constantly busy.
>
> Unfortunately VACUUM takes long (several hours) on this huge table, so I
> can't add in the loop after the DELETE command.
>
> Is there a better way to avoid the bloat in the loop above? Why can't
> the DELETE command update the index by pointing the minimum element
> beyond the dead tuples?
Any comments on this one? It annoys me that a simple loop deteriorated so
much and kept filling the table with bloat. What is that VACUUM does that
DELETE can't do, to keep the index fresh?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: jimis@gmx.net
Subject: Re: Moving data from huge table slow, min() query on indexed column taking 38s
In-Reply-To: <68257d84-96e5-9dca-ff31-c9f45e356543@gmx.net>
References: <096aa4b3-892e-7fa5-7370-3a1895e7d6a0@gmx.net> <68257d84-96e5-9dca-ff31-c9f45e356543@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox