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 1w6Yld-004Pxt-1w for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 18:52:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w6Ylc-00EwiT-0E for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 18:52:16 +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 1w6Ylb-00EwiF-2K for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 18:52:16 +0000 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w6YlZ-00000001X5I-3SEd for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 18:52:14 +0000 Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-89a06bc2f1bso51206296d6.1 for ; Sat, 28 Mar 2026 11:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774723933; cv=none; d=google.com; s=arc-20240605; b=bh2d1KWsDbu3kQyfmEpFXRsldQkeEFJ4PiaAtBJ85T/RFvakWCuywBBBMytSpU8p1u ikl/NMRUpbMAPEXY93dQzkPCwZVzFJzPSQIZCc94dII/Ny6XmH9jCiL+vBqOwUfIYXPl 0kG1JOlfKLT2qQNPPFW3p5/+TBTQBF1Wu0DByjfiZj6rJJRvrvUbeMGh+38S1UuefJK6 Ka13+UyIvmk4rQFaH1R+0ytyqqDrMHUD1Spz/EUw87kedsBuWztvk4M+EvOphuPQhT59 Dz5oereommL5PrKzDq4HZvKxMGkT5Wa/BZ7MWtZGM2iGLtON/4A/Rgry2DiP5NCUG+/z GqWg== 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=hXKHRuOpzd0u11wGspQt2tZLvyYFckk+48xlg4COjJQ=; fh=izcfppq/vRTC3oKjxSwUepPQboqJ4Qttb8eOu7A+5AU=; b=A2l3GBJXpDc2wvaEJVQdiN2ejAJvs6qIerbC6kGoTX+Livm5JEKyPq36fwX3qRWYw6 qlzNeoWqfV/xq1UZlWHirq7ATveQe5jiwbTVvAaOFCfzmG2SMGfiJPSu1DBUrdE1qvOQ zGrf90sRqmFGiVqr7EU4wvggphN/2vV+xKPnprzYuC0aWn8wMvUFFNOADIaDUW0+rhyz iDuz7utqvJIVBMz3/D0V87R007Qn81zjSmD8d03HKwTJ1GDN8jUGLYnZ8WauoQUJI4Hi EzhU8+Am1TckAMe9egc+7fW+nKaPdw2hvW674DoW2M+enGdLjMlIq0s3WmRVN87mZ5ca CZLA==; 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=1774723933; x=1775328733; 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=hXKHRuOpzd0u11wGspQt2tZLvyYFckk+48xlg4COjJQ=; b=mr4jJcABsmdPO+QUHWysAvytk/iqVOaMGHwhyXzTZAOE0zFZ/3urYlhWQzUWjUbOT0 MpG5mPaWKrjx6jGU1mDkFrP93r8Bb8y+MVdLNH0GXnxHPX7vksKTY3pKxPQpXVaw50z6 /bFgM+li1HSKciWy8daWNLIJQXUL7ygjRuQAg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774723933; x=1775328733; 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=hXKHRuOpzd0u11wGspQt2tZLvyYFckk+48xlg4COjJQ=; b=peYRnUU9D2V5AXmfZYLP+U+igBXaQdRPi9vA/VUUrCg+Y6iaAyqiPRasrK3P+bL5eH WU+ZFDVJAedyQ4JINPeo2Bz6/7rTjF5fzg/aymSNiEwLpai9swcRAADXDzFE3ebbad5b QRuT3Ub94untnojdYffcKm2/gfshSUY1Eu1SAUwfrhOqhPF/gQVihLWLqfiRDnEyHS3t U27fUrug2oVzzk1dMxSLWdscTHrpvL2WZIxLFVRIp6Jc77Wk++XTJvBb+XvrYPCqmHbW Frz8XYAzuz5KLCKGC9xDK+OpaddvYfdq+ut8KB9fbVwHGG6XE7O5xRoxp8cr9yoa18YU EaIg== X-Forwarded-Encrypted: i=1; AJvYcCUuPR4946ltMSr0gHATTP7Y1pYGiRwNQ7LNlhng5/1+C186spBp/9jdJ4aipzUn5G0mxhh/tPRK8wx3Wn2B@lists.postgresql.org X-Gm-Message-State: AOJu0Ywk5WfjS/Ich6WmmSL0UmctGWFyrDAHUKfOETnDUmcqqrsqFsjz oYcJF7cwSGYut+9kXWVIGnGXn8DckZ1r030C6XdCCyFov1Qdy4zLdjb8cEI6hP7vvjczklYgE+5 U+fAeHJIEb3rWrdpMXKC6Sget4aPfrQQvzQxep+Dv X-Gm-Gg: ATEYQzygnLZzLhhotdOo32KlppQMDJ0kqMZFq6Gnty/CyOFlbcgIY78XOgY5IFnObL9 LNTiLVkiPkC7xbPDPLsfYICCa2EsCEvJQW4hBWYa0FNeZYxNyKTZNRdjKfYbE+vMLuGpvwa6sL4 awd33O014JnXivX16WgNwiSWsF63QCk6eMJTUZDyPtgnof8m8nIVK/3i/1vQsWCuAIKsl31eAnW ffiI5jahWbMQ4GzQsGR+V0DOzWzJOFiTFh5BHP3vx3r7g5me6z4a+DGTiYCt1U9fqUd2fr0Myq8 0QzzLonA+Md9g3ZuPWSeRUksfMaA7IxEiWlNMeACtD2lZAa4nQA= X-Received: by 2002:a05:6214:498f:b0:89f:a232:8b9a with SMTP id 6a1803df08f44-89fa2328bf2mr25004656d6.33.1774723932965; Sat, 28 Mar 2026 11:52:12 -0700 (PDT) MIME-Version: 1.0 References: <670b867e-6518-48b0-b7c2-bd5f10ab58c6@vondra.me> In-Reply-To: From: Lukas Fittl Date: Sat, 28 Mar 2026 11:51:36 -0700 X-Gm-Features: AQROBzAMTnF197CIu5XhmRK8cVVykkVht9gzjbO6zuXby2sgnSl2CuXZGA6drXA Message-ID: Subject: Re: pg_buffercache: Add per-relation summary stats To: Masahiko Sawada Cc: Tomas Vondra , Ashutosh Bapat , 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 On Fri, Mar 27, 2026 at 10:37=E2=80=AFPM Masahiko Sawada wrote: > > On Fri, Mar 27, 2026 at 3:58=E2=80=AFPM Tomas Vondra wr= ote: > > One thing we lose by doing ad hoc aggregation (instead of just relying > > on the regular SQL aggregation operators) is lack of memory limit. > > There's a simple in-memory hash table, no spilling to disk etc. The > > simple pg_buffercache view does not have this issue, because the > > tuplestore will spill to disk after hitting work_mem. Simplehash won't. > > > > The entries are ~48B, so there would need to be buffers for ~100k > > (relfilenode,forknum) combinations to overflow 4MB. It's not very > > common, but I've seen systems with more relations that this. Would be > > good to show some numbers showing it's not an issue. > > Good point. I agree that we should not introduce the function in a way > that there is a risk of using excessive memory while not respecting > work_mem or other GUC parameters. Yeah, I agree that is problematic regarding work_mem. FWIW, I could see two methods to address that specifically, if we wanted the special purpose function: 1) Error out if our hash table grows too large and require the user to increase work_mem to get the data - seems inconvenient, but might be okay if we are typically below work_mem limit anyway (I haven't run the numbers on that yet) 2) Implement disk spill logic using a LogicalTapeSet or similar - I think that'd be substantially more code, doesn't seem worth it just for this (but if a situation like this recurs, we could consider a more generalized facility) Thanks, Lukas --=20 Lukas Fittl