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 1lBElu-0006DH-Ip for pgsql-admin@arkaria.postgresql.org; Sun, 14 Feb 2021 10:36:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBElt-0000bP-5z for pgsql-admin@arkaria.postgresql.org; Sun, 14 Feb 2021 10:36:57 +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 1lBEls-0000bI-Sh for pgsql-admin@lists.postgresql.org; Sun, 14 Feb 2021 10:36:56 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lBElm-00029S-98 for pgsql-admin@lists.postgresql.org; Sun, 14 Feb 2021 10:36:55 +0000 Received: by mail-qv1-xf34.google.com with SMTP id 2so1956897qvd.0 for ; Sun, 14 Feb 2021 02:36:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-id; bh=HmWg4HgQJABa7KRhDYL5SnQ4LmJlkewBnggimRFXBwQ=; b=KIpWlMoYXocdjBhlgDjmsjMz3WknjECvk+MBRPg4iOma+OMRWcMDjL/xoYFvSdN+iX pjJ6LzU/6SFJz/vwo2o7wD66johCwdafmjVjvWV5Xj73u8SJay08WwE1owc2VKmqAzwH ICqeBlATQE0Zq70pEBObE6eFVp4EEwknX89h+JsowcRgmccGz2GMkeHS2KQzv/NHHLUs +SnRrjkNGctrc/UcrGwaBLNsS8td3x4ifq6K8erb58/EPKq33xgPwKjzB7g54zfe+WhF nsAcZprbkTBa8N0DMtLcRoB+514RTiG0ZNP0eRWxrGnhztgXCfzek1ZmPWvPSJcBmRKg QBdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version:content-id; bh=HmWg4HgQJABa7KRhDYL5SnQ4LmJlkewBnggimRFXBwQ=; b=g3D/t372QqDAhkJjnwH+eCu9jIiCchEYomleLZdTDyy3aIqzN+XcgNyl85hF5+rkVR wOGMpZ3OIz3M6+oMg4VRVBWHo5cjWYi2YM/0FxqcopUrI9bupew/9z+ca/RCzFuUcUZg cSpbOiIK1jP5iZffc1jo1dnD4BP/iGfnz1O6W15nDPcFqrPlKelhwiVySQZqFDXbj4Dd DLS3dGt1wg97f3szNnAZZBAuo7Pn38gtXZ4/FLB77y6npebjXrH5HUew7rkK7l7CDl1E dkV1XAs0zAWtNbX3cOh1vk4tNY0J4P4M0yv42nRPfBhuzSgHdybBXNSusHoP+/XahiaP bE7Q== X-Gm-Message-State: AOAM533uRIuZKGN6hdwh1FdcWtD+Ov5IQDHQqgCwrNTEPnYWFfqYUNrc p3oYONAL/uA09sqFQrmFJzGv50H4YQsbZg== X-Google-Smtp-Source: ABdhPJwiS4ozD1woarWTimhiK44XbemdSyXccs8YfqCX9eT6ikKJJTxwo09b5l+tdcVAbgMlFIDc6g== X-Received: by 2002:ad4:5ce8:: with SMTP id iv8mr4492460qvb.16.1613299009314; Sun, 14 Feb 2021 02:36:49 -0800 (PST) Received: from fragile ([71.179.240.8]) by smtp.gmail.com with ESMTPSA id x62sm9763110qkd.1.2021.02.14.02.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Feb 2021 02:36:48 -0800 (PST) From: Gregory Smith X-Google-Original-From: Gregory Smith Date: Sun, 14 Feb 2021 05:36:47 -0500 (EST) To: Victor Sudakov cc: pgsql-admin@lists.postgresql.org Subject: Re: index bloat estimation In-Reply-To: Message-ID: <8a25e72c-6054-3e1f-b43-8f92111d2acb@fragile> References: MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="0-148001315-1613298286=:41952" Content-ID: <197af6d-b82e-21bb-bdb3-ccdadd97c5c8@fragile> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-148001315-1613298286=:41952 Content-Type: text/plain; CHARSET=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8BIT Content-ID: On Fri, 12 Feb 2021, Victor Sudakov wrote: > Most of the stuff I've looked at is pretty old, much seems unsupported. > What is the current best practice? None of the estimate queries ever really worked well. They just gave a bit more information than zero in the days before PG's internal functions were really reliable and useful for bloat measurement, something that happened in version 9.5 development. For any modern PG, it's worth the trouble to learn how to directly use pgstattuple https://www.postgresql.org/docs/current/pgstattuple.html to do this job. You run and interpret the output from pgstattuple(relation) and its faster estimate version pgstattuple_approx. It's not hard to run some simulations with deleted rows to see what bloat looks like when it builds up. There's still some need for manual estimates if you want to account for fillfactor in all cases, but I see that as a niche topic, not where people should start at. There are also wrapper scripts built on top of pgstattuple around, like the already mentioned https://github.com/keithf4/pg_bloat_check A good bit of the work done in that script is around handling multiple versions of PG and building some long-term idea of bloat state on all tables. Workloads that have a bloat problem are sometimes fixed, but in a lot of cases the best you can do is monitor them and rebuild things when it gets bad. That's one context Keith's packaging of this feature aims at. -- Greg Smith  greg.smith@crunchydata.com Director of Open Source Strategy Crunchy Data https://www.crunchydata.com/ --0-148001315-1613298286=:41952--