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 1m4QYl-0004g9-44 for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 16:19:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m4QYj-00023k-R7 for pgsql-general@arkaria.postgresql.org; Fri, 16 Jul 2021 16:19:29 +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 1m4QYj-00023c-HU for pgsql-general@lists.postgresql.org; Fri, 16 Jul 2021 16:19:29 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m4QYh-0004nm-EP for pgsql-general@postgresql.org; Fri, 16 Jul 2021 16:19:28 +0000 Received: by mail-wm1-x334.google.com with SMTP id l6so6211150wmq.0 for ; Fri, 16 Jul 2021 09:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VJUfkbHZPK2QoL0NOhnvM8sdsDWTdmZnLwHLiljx4CM=; b=Y2NmDqHO8m2JNNbAY7WRa40zzpL5xJj9Hk9r604dLyWcKG2LJXhVIVRdm6DF47d+KI eagJTUdvFJSGZDkawbA67bZSNDEn9pqY2thk05+CCBYJYyzMLwe7tl3PiDy62cP8huvN 3Y8//G5Uw0PXNSc5tjaxZbX01nGDkgM/LWfntxnkb8L1ZOQvaU25aUN4sMruheincGUE 9sQ3x5/CsSBxrtz5bsIhgaRymOSSrNn8BsfjK8N+1JXRqRZHvgeTFpQ6nCZa1kz5rmHd PJFWvxPLayDLNcRGXcQOFo8XT3OIblmJ+LIQR9U63jdH+045DMCj1lZASCqZJ/bjIXQf 4JbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VJUfkbHZPK2QoL0NOhnvM8sdsDWTdmZnLwHLiljx4CM=; b=kewKAosqPERUknl5WU/K0VortOcbBh+ENfp6cdSrN5ZUet7Y8CBC21YsRcsrXCSbUF tJQ8Gkt+U69zr7ewxacZiL3YvnBM6E7wowkV8dIW0rhJdPhclVWWD3DoZZVVcqk+ToBO Y3IIUxawzpWWEA8OKDjJ2pVF0DIyKxcjFM0n24/UlsRwrOK82KjTFC/6ERxGi9jLr3PJ K4MhNq8XmAjnp98mrcXmlOcQdVTZ65D3ygXkkkxjzzmd6kgGoPOO/6KLnBpU5jE5JUur rmkDb62XA8khBO6+ddw/5s1Pizonxivz6Dt1CoqXBbjM3BBA9zhfZDF+CXTN5ebPw9sk 9twA== X-Gm-Message-State: AOAM533k6+Q3CHB5mSK+HtyzIHcZecK+/dmuaErE0i6PKq7B8QfvfpiI RY3TgEOaxEfgDR9QVVGXNBERxFFxjFPL/w== X-Google-Smtp-Source: ABdhPJx0JeTuIx5GD3Ba83MIRvx/UoNjNO3tHO5t3w79VI2WietrcWetnoX2E1uPQlwoIXP4n5q7Yw== X-Received: by 2002:a05:600c:154d:: with SMTP id f13mr11411998wmg.3.1626452365554; Fri, 16 Jul 2021 09:19:25 -0700 (PDT) Received: from toms-imac.volo.voidbridge ([80.87.23.218]) by smtp.gmail.com with ESMTPSA id j23sm5261105wmo.26.2021.07.16.09.19.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jul 2021 09:19:24 -0700 (PDT) Content-Type: text/plain; charset=utf-8 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 From: Tom Dearman In-Reply-To: <3738900.1626450215@sss.pgh.pa.us> Date: Fri, 16 Jul 2021 17:19:24 +0100 Cc: Michael Lewis , Peter Geoghegan , pgsql-general General Content-Transfer-Encoding: quoted-printable Message-Id: <8563E084-A6B1-41E6-BCAB-B7D31E75C981@gmail.com> References: <95D506BA-D1E8-45BB-8167-BD61ED3D9B9C@gmail.com> <3738900.1626450215@sss.pgh.pa.us> To: Tom Lane 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 Other indexes do bloat, but the percentage bloat is a lot less, = presumably because this is a partial index where the partial column has = a high degree of changes ie maybe 100 genuinely =E2=80=98live=E2=80=99 = rows in a table of 300 million where every row has gone through a state = where it would have been in the index. In some of our partitions we = might have 2000 old rows that do hang around for a long time and another = 100 or so =E2=80=98real=E2=80=99 partial index entries so 2200 in total = but the number of rows would be 300 million so it is a lot less than 1%. > On 16 Jul 2021, at 16:43, Tom Lane wrote: >=20 > Tom Dearman writes: >> We have change autovacuum so that it runs more frequently = autovacuum_vacuum_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 have 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 status=3D=E2=80=98IN_PROGRESS=E2=80=99. In = theory it works well, but we get 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 completed statuses.=20 >=20 > 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. >=20 > 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. >=20 > regards, tom lane