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 1w6ZUc-004Qla-0c for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 19:38:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w6ZUa-00F36Q-2U for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 19:38:45 +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 1w6ZUa-00F36H-1Y for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 19:38:44 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w6ZUY-00000001hcr-1J3o for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 19:38:44 +0000 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-8d0288d24f6so98572285a.0 for ; Sat, 28 Mar 2026 12:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774726721; cv=none; d=google.com; s=arc-20240605; b=Dc6M8nPQ1MTkN2ibErIwdwDG2y0/7v5G/WKsITNB1x4Cmb0K013Ic01EmKgUCQhdrQ f6T4q/hMmSQqog02TMldpo0wL3kznUZO4VHXOSkxvasyKpXvZtPpTUPXQMOo/UVTxOJv WUiHOZFDK6oKPBFeAoGYwan8U4A9vS2hawVS9rk+NP+AgH9pmLRR7jtw8ffgRAy2hLB6 4T4uYdT4jhObCBZvzzcNkrAIxkZdAtFKz8EryGTaf1ytbyfLPDXmwc56e9F/SsFzaH7A Q3lvq1GLGkNCzK6ypLKnFvYh/7POzLNb7zm2lcPYd/hTTFA5X9bsGB2DHJbREEVpilYF rFXw== 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=jH0RK3Pzp7P6dxaYzGB9V2wUihMc+TyNKqVK7Cq/Soc=; fh=PCu4x3X4xNGeaqZgex/ThirMfkG+BsckUbXhY2SoS20=; b=YvmDY6gx5b8ethoypa9Nj2mafwGC3Og61PvObfDteno1N43dBwMqrg/fsopfuqlVeo B1YyrSQsu6a+XKhXDI8Ig4Cv8OcQt8HdcF0caa8Oz7Kt3LRMqo1HwfNzSxmG6OAwWB2C ISTb+2Kd9o3VfntDBIgjfsJ92DaQXYpCpWPVYBJcHVe/uEjGY3FMg0XQe0Eh5nGx+DD1 RemvdwNSNA/bE65m0fep0AGvSZFD0lnpzPhJwDFYbkNNK3LCtV3pqSEyBBZfo9RnTFa6 Lenp5jQmZ+HGciv6PqUjWqI6KV6rN1AL1cG931iFGHiV2UFKZRlDTVJIwFntS18sDX6Q 004Q==; 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=1774726721; x=1775331521; 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=jH0RK3Pzp7P6dxaYzGB9V2wUihMc+TyNKqVK7Cq/Soc=; b=V2zbZWC8CIcpFxN9kweP+6aEo+Q8LHb4h/2AQQaFD8/oPG3We06YHEm3wyjvT7Zvwb oHn6kMq0wdeZ2l4ENu7KKk7HectQzs6LOkZGjXTZmbgGv2FIr8nMpu2Ho13X7Vt+uvn3 j6g+BOYQqcwov6u9auup/mcGDhJx1mNwXHz4M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774726721; x=1775331521; 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=jH0RK3Pzp7P6dxaYzGB9V2wUihMc+TyNKqVK7Cq/Soc=; b=dyDI5c/IVj8h8WAHQeIvtAnsLnwjX81mDNx40TIxk1YPVytfryC5k7uI/UIY7aAZ12 hm5x2NIifEQ4kyq/scmPT7mgge6DiRKnXs0rq4Kdw6CMjfHU//chCjXPUjGC7ip5XAeq Jv7Hg3SmtmgH3OVBdhJDckP+M4Nalhr854+05ZOyeQebL4s6jLWYSCOuqTrRoda9B4Uv AcCKchMtkq/sVuLKwRoXfouauMZV18T/r4F043leXyVHO6NQBJZ0EX+4oeLBVQa7bvRl m3k1mCwfHd8HQRySA5/eBruhmhxmF2BQuKl8quYHAqDpURuwPIcp0eRAhepBgQo2B7Mw ANVA== X-Forwarded-Encrypted: i=1; AJvYcCWl8Zg3pYn4pGQX+TDGXiVsg9/eVXoxSRbrQSnZ40nD1pBmlKpG6nIvZ1hCAmzN83hdqJ3VeH1NmjoX4Pes@lists.postgresql.org X-Gm-Message-State: AOJu0YyQpiH3Bom5JQ+0PJGdUtA8vcFZNr2WKhT2brFWvlWMSnXogIUY YHDHwjACzddPuPjsGBxy6TPlQUQW21OL3aHj7nq2I1s7HZlRQz5OOwS88BAJ+u/Ux86vD7lZect Nl/fgmRV8kmfS68oEYr0RDAGhS9E5JW/wjyHxE5BV X-Gm-Gg: ATEYQzx60bbARAet+vazstxu6rAm0gwVtDMU0MP10a9oS2fFayehYuYdNhV84CWONsR VbAPYFyY2UQVMiI2S2kjNE24SLpj9q9zztBm+ba8y/E8Ddz3vaLDnEym+qQNTAHQIoNakO/Y+Rl BQ6EoqpqVn/sUoPoAG3hwrSQ85EVk3xJjByj278xryuKR2OYAfuLLXFEvAJJxjFLOSP9kMyq5OY Mbz2a51QrMAudcZrCoNh74AmQcXDxPd96yh3lRtI9xsBSQAA3+XCOqt+JJQwH0ylYDF5gPGdiDH jPhoaN1dudLZUYozFdd0zssAZrpfonvfTj4xA7Eo X-Received: by 2002:a05:620a:3181:b0:8ca:3715:eea5 with SMTP id af79cd13be357-8d013fffeffmr1169582585a.14.1774726720636; Sat, 28 Mar 2026 12:38:40 -0700 (PDT) MIME-Version: 1.0 References: <670b867e-6518-48b0-b7c2-bd5f10ab58c6@vondra.me> In-Reply-To: <670b867e-6518-48b0-b7c2-bd5f10ab58c6@vondra.me> From: Lukas Fittl Date: Sat, 28 Mar 2026 12:38:04 -0700 X-Gm-Features: AQROBzBfnHRhyd_9TMpDefV6hZV_5kedDXzZkpHU_H9UViyTpW8C9BERpFmAS8o Message-ID: Subject: Re: pg_buffercache: Add per-relation summary stats To: Tomas Vondra Cc: Ashutosh Bapat , 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 Tomas, Thanks for reviewing - just a quick response on your code review comments specifically: On Fri, Mar 27, 2026 at 3:58=E2=80=AFPM Tomas Vondra wrot= e: > I gave it a try on an azure VM with 32GB shared buffers, to make it a > bit more realistic, and my timings are 10ms vs. 700ms. But I also wonder > if the original timings really were from a cluster with 128MB, because > for me that shows 0.3ms vs. 3ms (so an order of magnitude faster than > what was reported). But I suppose that's also hw specific. Yeah, those initial numbers were from my Apple Silicon M3 ARM laptop without any special configuration, just for reference. > A couple minor comments about the code: > > 1) Isn't this check unnecessary? All entries should have buffers > 0. > > if (entry->buffers =3D=3D 0) > continue; Yeah, good point, that is there to protect the division for the avg usage count, but I agree in practice this shouldn't be reached. I could make it an assert, just in case. > 2) Shouldn't this check BM_TAG_VALID too? Or is BM_VALID enough to look > at the bufHdr->tag? > > /* Skip unused/invalid buffers */ > if (!(buf_state & BM_VALID)) > continue; > Good point, I think that makes sense to check BM_TAG_VALID here as well. FWIW, the function as-is does not lock the buffer header with LockBufHdr (intentionally to lower overhead), which means we can read a stale relation reference. I think that's okay for aggregate level / monitoring type information, but just want to call it out in this context. > 3) I think "buffers" argument should be renamed to "buffers_unused" for > consistency with pg_buffercache_summary. I assume you meant "buffers_used" instead of "buffers_unused" - assuming yes, that makes sense for consistency. --- I'll hold off on posting a new version for now, since I think we'd have to figure out a solution to the work_mem question at the very least, and it sounds like right now its also a toss-up in terms of overall interest to get this committed. Thanks, Lukas -- Lukas Fittl