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 1m4Q0B-0003mT-B2 for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 15:43:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m4Q09-0005VG-54 for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 15:43:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4Q08-0005V8-SF for pgsql-general@lists.postgresql.org; Fri, 16 Jul 2021 15:43:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4Q05-0004Vj-SP for pgsql-general@postgresql.org; Fri, 16 Jul 2021 15:43:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 16GFhZsN3738901; Fri, 16 Jul 2021 11:43:35 -0400 From: Tom Lane To: Tom Dearman cc: Michael Lewis , Peter Geoghegan , pgsql-general General Subject: Re: Frequetly updated partial index leads to bloat on index for Postresql 11 In-reply-to: References: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com> Comments: In-reply-to Tom Dearman message dated "Fri, 16 Jul 2021 15:58:01 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3738899.1626450215.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 16 Jul 2021 11:43:35 -0400 Message-ID: <3738900.1626450215@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tom Dearman writes: > We have change autovacuum so that it runs more frequently autovacuum_vac= uum_scale_factor=3D0.035, the reason we have a partial index on the status= is that in a table of 300 million entries, only about 100 or so would hav= e status=3D=E2=80=98IN_PROGRESS=E2=80=99 so we think this should be a nice= small index and many of our queries want to look up with a where clause s= tatus=3D=E2=80=98IN_PROGRESS=E2=80=99. In theory it works well, but we ge= t a lot of index bloat as there is a lot of churn on the status value, ie = each row starts as IN_PROGRESS and then goes to one of 4 possible complete= d statuses. = Is it really the case that only this index is bloating? In principle, an update on a row of the table should result in new entries in every index of the table. A partial index, due to the filter applied to possibly not store any index entry, should in theory have less bloat than other indexes. If that's not what you're seeing, there must be something about the data being stored in that index (not the partial-index filter condition) that results in a lot of low-occupancy index pages over time. You didn't say anything about what the data payload is. But we've seen bloat problems in indexes where, say, every tenth or hundredth value in the index ordering would persist for a long time while the ones in between get deleted quickly. That leads to low-density indexes that VACUUM can't do anything about. regards, tom lane