Re: pg_buffercache: Add per-relation summary stats

From: Lukas Fittl <lukas(at)fittl(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>, Khoa Nguyen <khoaduynguyen(at)gmail(dot)com>
Subject: Re: pg_buffercache: Add per-relation summary stats
Date: 2026-03-25 07:29:20
Message-ID: CAP53PkyoA2Thy8p04gL8d965DjUxX2=WcJzY6PbK-21v5fzTfA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Masahiko-san, Paul and Khoa,

Thanks for the review!

On Tue, Mar 24, 2026 at 12:09 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
> ---
> - pg_buffercache--1.5--1.6.sql pg_buffercache--1.6--1.7.sql
> + pg_buffercache--1.5--1.6.sql pg_buffercache--1.6--1.7.sql \
> + pg_buffercache--1.7--1.8.sql
>
> Since commit 4b203d499c6 bumped the version from 1.6 to 1.7 last
> November, we think we don't need to bump the version again for this new
> feature.

Makes sense, adjusted.

> Can we move these typedefs above function prototypes as other typedefs
> are defined there?

Makes sense, done.

> + relstats_hash = hash_create("pg_buffercache relation stats",
> + 128,
> + &hash_ctl,
> + HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
>
> It might be worth considering simplehash.h for even better performance.

Good point, adjusted.

> + while ((entry = (BufferRelStatsEntry *) hash_seq_search(&hash_seq)) != NULL)
> + {
> + if (entry->buffers == 0)
> + continue;
> +
>
> We might want to put CHECK_FOR_INTERRUPTS() here too as the number of
> entries can be as many as NBuffers in principle.

Sure, that makes sense.

> We've discussed there might be room for improvement in the function
> name. For example, pg_buffercache_relations instead of
> pg_buffercache_relation_stats might be a good name, since everything
> in this module
> is stats. if we drop "_stats" then "relation" should be plural, to
> match other functions in the module ("pages", "os_pages",
> "numa_pages", "usage_counts").

I've renamed this to "pg_buffercache_relations", though per Bertrand's
earlier email, I could also see that it makes sense to incorporate the
fact more clearly that we're returning physical relfilenodes, not
logical relations.

See attached v2 that incorporates the review feedback.

Thank you all for reviewing!

Thanks,
Lukas

--
Lukas Fittl

Attachment Content-Type Size
v2-0001-pg_buffercache-Add-pg_buffercache_relations-funct.patch application/octet-stream 16.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-03-25 07:39:47 Re: generic plans and "initial" pruning
Previous Message Jelte Fennema-Nio 2026-03-25 07:27:05 Re: Proposal to allow setting cursor options on Portals