pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Dearman <tom.dearman@gmail.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: pgsql-general General <pgsql-general@postgresql.org>
Subject: Re: Frequetly updated partial index leads to bloat on index for Postresql 11
Date: Fri, 16 Jul 2021 15:24:01 +0100
Message-ID: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com> (raw)
In-Reply-To: <CAH2-WzmoZBJXYcaBKt2Zjyy-RXiHRsCQyXTcZKiB+n1C4kteTw@mail.gmail.com>
References: <CAGRwtPy0stc_XSuWdxis7GtvVUV2=xWjsd-g4hjzOSaTi5L72A@mail.gmail.com>
	<CAH2-WzmoZBJXYcaBKt2Zjyy-RXiHRsCQyXTcZKiB+n1C4kteTw@mail.gmail.com>

Hi,

We upgraded to 13 a couple of months ago on production but are still having an issue with bloated partial indexes which have an impact on our partial queries especially towards the end of a quarter when our quarterly-partitioned tables are getting big.  I have built 14 (on macOS catalina, 14 beta 2) and run a test but the index grows fairly large (even though vacuums are running as the table is still relatively small - I put in 2 million inserts, each having one update of the column that makes up the partial index). The table is:

                                                     Table "public.buyer"
    Column     |          Type          | Collation | Nullable | Default | Storage  | Compression | Stats target | Description 
---------------+------------------------+-----------+----------+---------+----------+-------------+--------------+-------------
 buyer_id      | integer                |           | not null |         | plain    |             |              | 
 first_name    | character varying(35)  |           | not null |         | extended |             |              | 
 last_name     | character varying(35)  |           | not null |         | extended |             |              | 
 email_address | character varying(50)  |           |          |         | extended |             |              | 
 status        | character varying(256) |           | not null |         | extended |             |              | 
Indexes:
    "buyer_pkey" PRIMARY KEY, btree (buyer_id)
    "idex_buyer_inactive" btree (first_name) WHERE status::text = 'IN_PROGRESS'::text
Access method: heap


I run a loop to insert, commit, update, commit one row at a time as this is an emulation of what a similar table would experience in production.  The index never has many rows with status=‘IN_PROGRESS’ as each row is set to CANCEL in the update.  If the index is reindexed it takes 1 page as expected but without the reindexing it keeps growing, currently reaching 3MB - this is with 2 million inserts and updates but our production will have about 300 million inserts and > 300 million updates on the partial index in the quarter.  Should we have seen more of an improvement in 14?  Is it valid to look at the size of the index (\di+) as a measure of whether this latest change to bottom up index deleting has helped?

Thanks,

Tom

> On 18 Mar 2021, at 16:30, Peter Geoghegan <pg@bowt.ie> wrote:
> 
> On Thu, Mar 18, 2021 at 6:51 AM Tom Dearman <tom.dearman@gmail.com> wrote:
>> Is this a known issue, are they any ways around it, and if it is an
>> issue is there a plan to fix it if a fix is possible?
> 
> It's not exactly a known issue per se, but I think the problem here is
> related to the fact that you have lots of duplicates, which did
> perform rather badly prior to Postgres 12. I bet that you'd benefit
> from upgrading to Postgres 12, or especially to Postgres 13. The
> B-Tree space management is a lot better now. (Actually, it'll be
> better again in Postgres 14.)
> 
> -- 
> Peter Geoghegan

view thread (10+ messages)  latest in thread

Message-ID: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com>
Permalink:  ../95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com/
Also on:    postgresql.org/message-id/95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com

 · 

reply

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: tom.dearman@gmail.com, pg@bowt.ie
  Subject: Re: Frequetly updated partial index leads to bloat on index for Postresql 11
  In-Reply-To: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com>
  References: <CAGRwtPy0stc_XSuWdxis7GtvVUV2=xWjsd-g4hjzOSaTi5L72A@mail.gmail.com> <CAH2-WzmoZBJXYcaBKt2Zjyy-RXiHRsCQyXTcZKiB+n1C4kteTw@mail.gmail.com> <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com>

* 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