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 1w5I1D-00367j-39 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 06:47:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5I1B-00CK0o-0k for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 06:47:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5I1A-00CK0g-2u for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 06:47:05 +0000 Received: from mail-qv1-xf33.google.com ([2607:f8b0:4864:20::f33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5I19-00000000vJ6-0fw2 for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 06:47:04 +0000 Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-89a465bd7edso17991206d6.0 for ; Tue, 24 Mar 2026 23:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774421221; cv=none; d=google.com; s=arc-20240605; b=e0czAlKTIggq8l91g6CNTUaq2KwZnO0Bjey+oNj1eZTxWg9CrRoy1P3vf3fV78FNCQ vxYVVgQ6shyhksC9EiAjzJYE2PTr11QS8jVk5xF8yCJU1cUmjPWKcLauDOyN1/w6Vgdy 60W6HbHxtQu5YkuIQ8jbKlaFohQy0gUoMGl6Us3Lfd6YE33LZFj/E6Hsx8tv0eq3j8+D m1YZa70emWsZIyf4hLNfOoYvNG2LD+eRAHG2pV4ukt2zEi2jtrK7obL5eFSD1cufAwOS k81+4IpLIKm95rLfidsKEDNID28qH5MEhZa/WoejkBG0MsLNWAHrRYFPQYNZdPe/1mKc dlGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=cQdPsuONSps2Bq6Eh7S8D19JjDOa6dJhi3Dr3Y5cuow=; fh=4pzNSuM3Gu3mpNnCFw+GMNk/EXucMcxajLJBSMa/8Dk=; b=aP0NdcnaAHZiK5vJAVt+i8Zaxtyd8NSI7Dy7nF55Ap3rg13jPZqTRfO+2IZirnqoT8 sDoCVRkqPh1TNU+h+WO0DlpxS0v9RWX+sNo592L8hqxZlSFUW90nbci7yVz+mqDG1HA0 IxZ3tb3wScCUZP6bijQAVxutciK5uukwaYwXuMq6CqBtKUIqnCwos+1XDhINt3+MfNRq 8+4oH1GLbKILEBrvXPGCOsLRIhajUkgHc/sTo1QJbKQ7sq/D9mRKeb9tkINLLoil5XEl AtvRqcB+APzSGar6CGdmhu/qCOgimiL6RBRuesedeLkfqb9jzdxJ1Nd+phB9lNfFFvPd 7dPw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fittl.com; s=google; t=1774421221; x=1775026021; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cQdPsuONSps2Bq6Eh7S8D19JjDOa6dJhi3Dr3Y5cuow=; b=IXnkO9Zu6x3LgW2OkQ3i84VuC/HFOKFCFs1PyJeghsai2L9/JEv2r9phHbVnuGa9nS in1mqFClnU1Slloqd1ZANWzm6HpM5HsBQ+DZkXk1DlySW56gbaUCPp87cv4/0FdxfMVo LfkAKlb2PuYHdKUGZXJaih9AxOHI4g8dvnSX0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774421221; x=1775026021; h=content-transfer-encoding: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=cQdPsuONSps2Bq6Eh7S8D19JjDOa6dJhi3Dr3Y5cuow=; b=DNqlLO+Cx0i52Tqs1Tx5Mklr7Uqc7CGfkKmtTPoLCLfHBM52m53fbk103CbHrRF1nC 3chi8D0GWunZW0G0zrYeMnoskNApNW6BR8eMj8nK4Pse6q067q8gOnnBLIXRsRJ5dw+N RJ7MeAvEA4aty67/zvUcexxbKJlDOpOC8ZSzKOhza0vpZ3pC6ECpAjBpLPDs4y6vD0Op cCzCTanLwNq6KpMT4+l2ZGBdB1mVGuwcwpzA8bgfBlFxscm54/EgiPI/k2Y7rc/+W+nT vLuvNWBIZYLKhlKbiEhhrwHFwfB9nqC/CP1DTw1AX958UOu2nn96H07PXP7Qf/hiImpa EfkA== X-Forwarded-Encrypted: i=1; AJvYcCVmd+jVWeq4FvGAD7Q3FTChPFLlLiQmG7dMloMWjpgqOHVmfmdXRm4B15QT0dVtAbkDbtQ9cqT+iEcCc2cZ@lists.postgresql.org X-Gm-Message-State: AOJu0Yz4XMPehVaPj/r155xQpdj2hR4dyw9Prrp9DPifljcInhA/gDhJ 2RiVsNwL1KNW+RxtDSrbNTyMDVwZvA09zjAnQtJ2wgZNBOw4EpuQrD4ZaCmUlRgDXPCQlG/N30N kYjKtujs9cO+FFDOGgfoayZ0ZiA4bhXwinCfGwsbq X-Gm-Gg: ATEYQzzEW93Q21zp4/FpZn5ZvJGjvU8QfTzzWYh5WXKRa6BjobrpJYQuR1GklhQ0RRh PURnJ8X38rcSe5Ajm9Zf9wluX78Ke+rc8UDDsRVz3QZHhRQmwDKg0nUwPCcsCHguLNakL6aT3Sv RFFKVxjFTaYbRvxQxPbsxCmLYXClIUA4HjO5k+hLpbbOD0pOWEpyL0d7rM/Osfroeux429TLk3R UXmH/StWOQaBcMDJUxjhFqF+xdtSwykIFzuTPZ8VH7eVgdagmdFuoDDZP5kz8PBnUqLcPRhQqP+ ui8OgTpSmttfbLBHKhLlN2NekbI+ExEhrMjhQF1/ X-Received: by 2002:a05:6214:5993:b0:89c:4fe3:85b5 with SMTP id 6a1803df08f44-89cc4ac2244mr36852046d6.52.1774421221202; Tue, 24 Mar 2026 23:47:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Lukas Fittl Date: Tue, 24 Mar 2026 23:46:25 -0700 X-Gm-Features: AaiRm50T_4dtQRv4tVPnA5veS52kWD2d-77OjwITuFDNYFGmlcEjrQ2hCtjehdo Message-ID: Subject: Re: pg_buffercache: Add per-relation summary stats To: Ashutosh Bapat Cc: Masahiko Sawada , PostgreSQL Hackers , Paul A Jungwirth , Khoa Nguyen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Ashutosh, On Tue, Mar 24, 2026 at 11:24=E2=80=AFPM Ashutosh Bapat wrote: > I know we already have a couple of hand-aggregation functions but I am > hesitant to add more of these. Question is where do we stop? For > example, the current function is useless if someone wants to find the > parts of a relation which are hot since it doesn't include page > numbers. Do we write another function for the same? Or we add page > numbers to this function and then there's hardly any aggregation > happening. What if somebody wanted to perform an aggregation more > complex than just count() like average number of buffers per relation > or distribution of relation buffers in the cache, do they write > separate functions? I think the problem this solves for, which is a very common question I hear from end users, is "how much of this table/index is in cache" and "was our query slow because the cache contents changed?". It can't provide a perfect answer to all questions regarding what's in the cache (i.e. it won't tell you which part of the table is cached), but its in line with other statistics we do already provide in pg_stat_user_tables etc., which are all aggregate counts, not further breakdowns. Its also a reasonable compromise on providing something usable that can be shown on dashboards, as I've seen in collecting this information using the existing methods from small production systems in practice over the last ~1.5 years. > Another problem is the maintenance cost these functions bring. For > example, with the resizable shared buffer project we have another > function to stress test. Can you expand how your testing would be impacted? I hear you on not adding many unnecessary functions, but the basic paradigm of how it iterates over buffers here is very similar to the other functions in pg_buffercache, its just shifting the aggregation to be at a different level. > Looking at the function, I see it uses a hash table to aggregate the > data. To some extent it's duplicating the functionality we already > have - aggregates using hashing. Are we going to duplicate > functionality everywhere we require aggregation on top of a system > function? These functions will then be missing any optimizations we do > to hash aggregation in future. Can we instead investigate the reason > the aggregation on top of pg_buffercache output requires so much more > time than doing it in the function and fix that as much as we can? I > know some slowness will come from tuplestore APIs, tuple formation and > deformation but I won't expect it to be 10 times slower. I don't think this is fixable outside the function, and I'd be surprised if you could get comparable performance, unless you had an extreme case where it was < 100 buffers per relation. There are just too many layers involved where we'd keep the full set of buffer entries vs the grouped version. I'm happy to be convinced otherwise, but I won't be the one pushing forward that effort myself. Thanks, Lukas --=20 Lukas Fittl