Thread: Get table total page quantity and cached page quantity

Get table total page quantity and cached page quantity

From
otar shavadze
Date:
created pg_buffercache extension:
CREATE EXTENSION pg_buffercache;

restarted server and updated statistic for table :
VACUUM ANALYZE public.my_table;

then just tried to cache table in buffer:
SELECT * FROM public.my_table;

and then tried to get table total page quantity and how much pages are cached in buffer for this table:
SELECT
(SELECT relpages FROM pg_class where oid = 'public.my_table'::regclass::oid ) AS table_pages_quantity_total,
(SELECT COUNT(DISTINCT relblocknumber) FROM pg_buffercache WHERE relfilenode = (
SELECT relfilenode FROM pg_class WHERE oid = 'public.my_table'::regclass::oid -- (SELECT rel_oid FROM my_cte)
) ) AS table_pages_quantity_in_cache;


 This shows that table have only one page, while second column shows 3 unique pages in buffer cache. Seems I'm measuring those numbers incorrectly(?) can you please help, which column is incorrect (or may be both) ?

 

Re: Get table total page quantity and cached page quantity

From
David Rowley
Date:
On Sun, 15 Aug 2021 at 23:41, otar shavadze <oshavadze@gmail.com> wrote:
> SELECT
> (SELECT relpages FROM pg_class where oid = 'public.my_table'::regclass::oid ) AS table_pages_quantity_total,
> (SELECT COUNT(DISTINCT relblocknumber) FROM pg_buffercache WHERE relfilenode = (
> SELECT relfilenode FROM pg_class WHERE oid = 'public.my_table'::regclass::oid -- (SELECT rel_oid FROM my_cte)
> ) ) AS table_pages_quantity_in_cache;
>
>  This shows that table have only one page, while second column shows 3 unique pages in buffer cache. Seems I'm
measuringthose numbers incorrectly(?) can you please help, which column is incorrect (or may be both) ?
 

This question likely is more suited to the pgsql-general mailing list.
My answer in [1] likely will clear this up for you.

If you need further information, please ask on that thread.

David

[1] https://www.postgresql.org/message-id/CAApHDvpHddfoZOviYXiz2dCr9emrrbnJ7n3HkS8KNsD9W1wscA@mail.gmail.com



Re: Get table total page quantity and cached page quantity

From
otar shavadze
Date:
Answer is pretty clear, thank you David.

On Mon, Aug 16, 2021 at 12:31 AM David Rowley <dgrowleyml@gmail.com> wrote:
On Sun, 15 Aug 2021 at 23:41, otar shavadze <oshavadze@gmail.com> wrote:
> SELECT
> (SELECT relpages FROM pg_class where oid = 'public.my_table'::regclass::oid ) AS table_pages_quantity_total,
> (SELECT COUNT(DISTINCT relblocknumber) FROM pg_buffercache WHERE relfilenode = (
> SELECT relfilenode FROM pg_class WHERE oid = 'public.my_table'::regclass::oid -- (SELECT rel_oid FROM my_cte)
> ) ) AS table_pages_quantity_in_cache;
>
>  This shows that table have only one page, while second column shows 3 unique pages in buffer cache. Seems I'm measuring those numbers incorrectly(?) can you please help, which column is incorrect (or may be both) ?

This question likely is more suited to the pgsql-general mailing list.
My answer in [1] likely will clear this up for you.

If you need further information, please ask on that thread.

David

[1] https://www.postgresql.org/message-id/CAApHDvpHddfoZOviYXiz2dCr9emrrbnJ7n3HkS8KNsD9W1wscA@mail.gmail.com