Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4PWK-0002tC-PG for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 15:12:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m4OlA-000519-50 for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 14:24:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4Ol9-000511-Om for pgsql-general@lists.postgresql.org; Fri, 16 Jul 2021 14:24:11 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m4Ol3-0000gr-4V for pgsql-general@postgresql.org; Fri, 16 Jul 2021 14:24:11 +0000 Received: by mail-wm1-x331.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so8324627wms.1 for ; Fri, 16 Jul 2021 07:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=AYsyXehb1q9NTCvbCQMhBs3WAKN+Sef5k+XU0HnR7Bo=; b=O7iuCVolRw7wQuoh9do6Y1psOY78Cm4tWbGgGNbmbmOcpDp2ADcP6B/SvV++CJxqQB IKYkPCnaHufNUD/W4suCCiSpTKbcH7gc54bXO44Qrjk5SgjNdwiXBcqUP1EZnyHZMNr9 Jp3/nwHYrViqjfGXenA6VKVXL1w0dvzj/2apLVJZwzX9KLi/ZU3HWsJ8/tmFSXiEFRvk 4PE3M3mdzkbcmvoU3VEXba/3+nBKr9Lxc7tXowvu3wB7FKYjTic8ItWbhnbYjuDDWV3Q OK8hEC4ucS+hQ0R/uTGI4/SV/VjXgX4A7jm1iF62OhaPmVr6pmbxX6qg7RbsAhxHGB5w EqJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=AYsyXehb1q9NTCvbCQMhBs3WAKN+Sef5k+XU0HnR7Bo=; b=UHJb8d5ul0MGUv9NdE1Z7td11miKqTNAJRzpbS2eFegMcP5ujKiuyssVaGafTfO++a a1J/THVwcePMECWtiLdwU1BiTjWhqxCZgxhh/61nHHAxBBTPIkKdD0DQSflWNiTAofPu 8TMoL5Jsj0BkUyQo/XB/T6aIbUV2CJT3DbDC3d2AZh9E/kiixV9Wp+SesdURrcQWY+YC 7sf9eGyQ4aEVU/QYAmmmo9+7u1lxMopbfPqhKFenLfDo+YGA2rEB1KWQwc1nC73qKy5J Uu8jZ1eSWD+YYzS01tNtlHfXiMOm1jtZaQCmjDkRtee5zXCo64xszeAXje+F/fN7qOgL 4C/Q== X-Gm-Message-State: AOAM530X3CkMmMRQa9UREP5dRUITqQsIncLnpkqtZyoPgQvzd1R9gbzB OHJrI3Db0me+k1Coo3LUXe0= X-Google-Smtp-Source: ABdhPJwwcOtnmhLfamaPAy7lZIX7CeDWgsjRsY2VoEiPOFX6sacdAgzchTuH1ttc4SJ7+NSrfH5bqw== X-Received: by 2002:a05:600c:4a17:: with SMTP id c23mr11039087wmp.7.1626445442635; Fri, 16 Jul 2021 07:24:02 -0700 (PDT) Received: from toms-imac.volo.voidbridge ([80.87.23.218]) by smtp.gmail.com with ESMTPSA id t5sm10235969wrw.38.2021.07.16.07.24.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 07:24:01 -0700 (PDT) From: Tom Dearman Message-Id: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_DD8650A1-7441-483D-B9F1-0F7FC3E2FDD9" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Frequetly updated partial index leads to bloat on index for Postresql 11 Date: Fri, 16 Jul 2021 15:24:01 +0100 In-Reply-To: Cc: pgsql-general General To: Peter Geoghegan References: X-Mailer: Apple Mail (2.3608.120.23.2.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_DD8650A1-7441-483D-B9F1-0F7FC3E2FDD9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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=20 = ---------------+------------------------+-----------+----------+---------+= ----------+-------------+--------------+------------- buyer_id | integer | | not null | = | plain | | |=20 first_name | character varying(35) | | not null | = | extended | | |=20 last_name | character varying(35) | | not null | = | extended | | |=20 email_address | character varying(50) | | | = | extended | | |=20 status | character varying(256) | | not null | = | extended | | |=20 Indexes: "buyer_pkey" PRIMARY KEY, btree (buyer_id) "idex_buyer_inactive" btree (first_name) WHERE status::text =3D = '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=3D=E2=80=98IN_PROGRESS=E2=80=99 = 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 wrote: >=20 > On Thu, Mar 18, 2021 at 6:51 AM Tom Dearman = 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? >=20 > 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.) >=20 > --=20 > Peter Geoghegan --Apple-Mail=_DD8650A1-7441-483D-B9F1-0F7FC3E2FDD9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 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 =3D '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=3D=E2=80=98IN_PROGRESS=E2=80= =99 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

= --Apple-Mail=_DD8650A1-7441-483D-B9F1-0F7FC3E2FDD9--