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 1mSdjV-0007cM-Qq for pgsql-general@arkaria.postgresql.org; Tue, 21 Sep 2021 11:14:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSdjU-0007bx-HP for pgsql-general@arkaria.postgresql.org; Tue, 21 Sep 2021 11:14:40 +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 1mSdjU-0007bo-8X for pgsql-general@lists.postgresql.org; Tue, 21 Sep 2021 11:14:40 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSdjQ-0007K4-Ud for pgsql-general@lists.postgresql.org; Tue, 21 Sep 2021 11:14:38 +0000 Received: from [192.168.77.84] (103-76-144-176.ip.cis.gen.nz [103.76.144.176]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id 18LBEWYK017198 for ; Tue, 21 Sep 2021 23:14:32 +1200 Message-ID: Date: Tue, 21 Sep 2021 23:14:32 +1200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: Question about behavior of conditional indexes Content-Language: en-GB To: pgsql-general@lists.postgresql.org References: From: Gavin Flower Organization: ArchiDevSys In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 21/09/21 22:28, Koen De Groote wrote: > Greetings all, > > Working on postgres 11. > > I'm researching an index growing in size and never shrinking, and not > being used anymore after a while. > > The index looks like this: > > |"index002" btree (action_performed, should_still_perform_action, > action_performed_at DESC) WHERE should_still_perform_action = false > AND action_performed = true | > So, there are 2 boolean fields, and a conditional clause for both. The > table has about 50M rows, the index barely ever goes over 100K matched > rows. > > The idea is to search for rows matching these conditions quickly, and > then update them. This happens daily. > > This means the condition no longer match the index. At this point, > does the row get removed from the index? Or does it stay in there as a > dead row? > > I'm noticing index bloat on this index and am wondering if all these > updated rows just stay in the index? > > The index currently sits at 330MB. If I drop and re-create it, it's 1.5MB. > > A cronjob runs a vacuum once per day, I can see the amount of dead > rows dropping in monitoring software. > > But should this also take care of indexes? In postgres 11, you can't > reindex concurrently, so I was wondering if indexes are skipped by > vacuum? Or only in case of conditional indexes? > > > > So I'm wondering if the behavior is as I described. > > Regards, > Koen De Groote Can you upgrade to pg13?  A lot of work was done on indexes in pg12 & 13.  So possibly your problem may have been resolved, at least in part. Note that pg 14 is due out this month. Cheers, Gavin