Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vIXO7-004hmX-28 for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Nov 2025 19:17:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vIXO4-0023cC-2v for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Nov 2025 19:17:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vIXO4-0023bz-1I for pgsql-hackers@lists.postgresql.org; Mon, 10 Nov 2025 19:17:12 +0000 Received: from mail-qk1-x732.google.com ([2607:f8b0:4864:20::732]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vIXO1-00721x-2b for pgsql-hackers@postgresql.org; Mon, 10 Nov 2025 19:17:11 +0000 Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-89e93741839so251481085a.3 for ; Mon, 10 Nov 2025 11:17:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=komzpa.net; s=google; t=1762802227; x=1763407027; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5iIymukT7SDmv1WyOUXe3n1aSMz6AkqcvwlIFKCoWCw=; b=PcCp/MArL1mX+a0yZOZJ1+sh7kF6fzi5tkoN7pzUtwwKMkqaMID0tw/fQqfCuoWcOt WYgBiIUaFwicKe3E7StYw+mq2dSv4rVSPHfv+bFMZmPzikslnejLN2DwpwalVgFuk0/k 3ECJFPttKORD3mh4qp55iXjFihuMlvPRkld5bFvQu2XubSA2GSrsjoxlAYeNRWvrQogB bzN4SyppmOdY0iGpHgOzL22W7mi4z1POHasNQuFFf+eNR7bQ1z4LZqv0T9p921ruGcvb hRq69nCeTjHi0HGGrCcHWvdf1Dv4jTrHJLtsx34XJepQeVXS47xS0EYfYcSsxBcA+ucX ivvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762802227; x=1763407027; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5iIymukT7SDmv1WyOUXe3n1aSMz6AkqcvwlIFKCoWCw=; b=AwBvLhSSWyFrwwjmxQnl0SXkxVAY2ckpnekM+vMCFDY1OXy6YK+bAnQRBlSIwRNGaK njeSJIWLYqMPTX7O/yLbfd5DnIA9U4U9XMhMNitV58K/HfySJD7aMg2MZf/qQ/MEW2tb IFTj3lK2l0NPiZfjoeWpUlBfgHSEes6+S9OedBUxRXrBrCD9zNybolA+sJa1wCjtthto O7Y2cNeG9aR715MeQBhdwCY3nrRYumNUG+M23LNqAgSTpzPMJtA0NMp2+rvLm26iS3md ekOyAPfkqxLZyo9CIHJ8cjSPtvTtMOO6Ybq86YvWQupXtWyiFmB/iZAw3pZVo/W5S5om VqVg== X-Forwarded-Encrypted: i=1; AJvYcCVKCJ0LzE+KMOyvAWiUO2nariXXKqm85OKi4MbrCEAddODbYIYO8rpIHsoxBbZXsTsJOjtz0rDtrt3l9DRM@postgresql.org X-Gm-Message-State: AOJu0YyogMvwbxcB7flk43V6k4fnIJg2qW8RypkNr7nMfdEugY56d9Ck /Anzsh/774jMJuEFFrusDPDleoMWaVeqsaTMJOcN928SSLRE//5wu9Ws0NltxDtpE4DnA7zoFb0 dacNlew== X-Gm-Gg: ASbGncu7gUqIrTsl8n5pC3VYjUfboEYzCJmYB1EO5Nk0q2bs/5ltJOjdLN8Y9TmVqTE Jo8FL4yTWuMGXLPSIFFBUMraj3IPGC3Y86qQlOKWpV5jLxFc5bELISZ9sbJi6d9ItuNgxjH22Gv IqOG2uRgNXL52nG4eEkHmZDi/XQ6tcGfkjLel2JQpKkA7/C0DssSBg13uwdbCuW8FZuf/9aQpRs vX6Fg+5lmBfL1siPMTq1ZqbKJXaJlImHV2JwWLh5aVhw6xbLAfvarCuuqoNBZ5y4wgifrC7Qq31 rHiuP1NGfGgj+rtIszB0t6lRTAjMxvdpsIqDx0/oU6fhC0MiCosbwR9P1uNqlbTOHVJS3Z2Jrw1 22eNbB3tjS5YTryrJ71d2Xevq/IYlJE8fCcCRavSgAd+0noGn/J9tN3OQCPY/T6iFxuxKhS745/ gg6baKDxcnQfZrALaok9dOqbR2OZWEJOJMKlVm4l4qNc0= X-Google-Smtp-Source: AGHT+IF7C00hUaD5p2S17csE7jWIim9Oq/y4wdy6Cb+Ye0W7QPG4yk+Ez3pV/KkS2VfoJBnEN8zozA== X-Received: by 2002:a05:620a:440d:b0:8b1:1585:225d with SMTP id af79cd13be357-8b257f76b5cmr1173438085a.82.1762802226537; Mon, 10 Nov 2025 11:17:06 -0800 (PST) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com. [209.85.160.182]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b262aa810asm491797685a.39.2025.11.10.11.17.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Nov 2025 11:17:05 -0800 (PST) Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4ed72cc09ddso18091101cf.2 for ; Mon, 10 Nov 2025 11:17:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWfBpqMMb0JDcnt4ELUusfdHIB2LzMdm4tegbS/+7MsyfV1XSuhKzIvj56y19DqOkCBZXVhNSWlkGpHjzOQ@postgresql.org X-Received: by 2002:a05:622a:48d:b0:4eb:a65c:90bb with SMTP id d75a77b69052e-4eda4fd6305mr107792551cf.73.1762802225130; Mon, 10 Nov 2025 11:17:05 -0800 (PST) MIME-Version: 1.0 References: <11A59C0C-A8C8-4642-8493-292D5DF8311D@yandex-team.ru> <3F0FC1DC-3653-4F61-A46F-46FF81C14915@yandex-team.ru> In-Reply-To: From: =?UTF-8?Q?Darafei_=22Kom=D1=8Fpa=22_Praliaskouski?= Date: Mon, 10 Nov 2025 23:16:52 +0400 X-Gmail-Original-Message-ID: X-Gm-Features: AWmQ_bmoaRkImqAv0KTGlDe4Ta2PzDUf9RhpLOgvUaO7vXG8L78wUjq3SG069pE Message-ID: Subject: Re: [WiP] B-tree page merge during vacuum to reduce index bloat To: Andrey Borodin Cc: Peter Geoghegan , boekewurm+postgres@gmail.com, pgsql-hackers , Kirk Wolak , Nikolay Samokhvalov Content-Type: multipart/alternative; boundary="00000000000070334f064342605f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000070334f064342605f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, On Sun, Aug 31, 2025 at 4:16=E2=80=AFPM Andrey Borodin wrote: > > > > On 29 Aug 2025, at 13:39, Andrey Borodin wrote: > > > > What if we just abort a scan, that stepped on the page where tuples were > moved out? > ... > What do you think? > We have a database on which we have bulk insertions and deletions of significant parts of the table. btree- and gist-bloat becomes a significant issue there so much that we have to resort to making ad-hoc cron-like solutions[1]. REINDEX CONCURRENTLY also sometimes crashes due to memory pressure leaving half-dead indexes behind which we have to clean up and keep reindexing until success. [2] Anything that improves the situation and makes Postgres handle this automatically would improve the experience significantly. Regarding locks: I think that baseline to compare to here is "what would happen if I had to REINDEX instead" and that is EXCLUSIVE LOCK at some point. I'd set that as a baseline for the endeavour. I think it may dramatically simplify correctness checks for the first iterations and relieve the pain for most of the cases. A similar mechanic for GiST will also be helpful. 1. https://github.com/konturio/insights-db/blob/main/scripts/reindex-bloated-b= trees.sh 2. https://github.com/konturio/insights-db/blob/main/scripts/drop_invalid_inde= xes.sql --00000000000070334f064342605f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

On Sun, Aug 3= 1, 2025 at 4:16=E2=80=AFPM Andrey Borodin <x4mmm@yandex-team.ru> wrote:


> On 29 Aug 2025, at 13:39, Andrey Borodin <x4mmm@yandex-team.ru> wrote:
>

What if we just abort a scan, that stepped on the page where tuples were mo= ved out?
...=C2=A0
What do you think?=C2=A0

We ha= ve a database on which we have bulk insertions and deletions of significant= parts of the table.

btree- and gist-bloat becomes a significant iss= ue there so much that we have to resort to making ad-hoc cron-like solution= s[1]. REINDEX CONCURRENTLY also sometimes crashes due to memory pressure le= aving half-dead indexes behind which we have to clean up and keep reindexin= g until success. [2]

Anything that improves the situation and= makes Postgres handle this automatically would improve the experience sign= ificantly.

Regarding locks: I think that baseline to compare to here= is "what would happen if I had to REINDEX instead" and that is E= XCLUSIVE LOCK at some point. I'd set that as a baseline for the endeavo= ur. I think it may dramatically simplify correctness checks for the first i= terations and relieve the pain for most of the cases.=C2=A0
--00000000000070334f064342605f--