Re:

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Michael Goldberg <mic(dot)goldberg(at)gmail(dot)com>
Cc: otar shavadze <oshavadze(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re:
Date: 2021-08-15 20:27:34
Message-ID: CAApHDvpHddfoZOviYXiz2dCr9emrrbnJ7n3HkS8KNsD9W1wscA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 15 Aug 2021 at 22:15, Michael Goldberg <mic(dot)goldberg(at)gmail(dot)com> wrote:
>
>
> On Sun, Aug 15, 2021 at 12:49 PM otar shavadze <oshavadze(at)gmail(dot)com> wrote:
>>
>> How measure table total pages (block) count? would be this correct way? :
>>
>> SELECT pg_table_size('my_table'::regclass) / current_setting('block_size')::BIGINT;
>
> Did you try:
> SELECT relpages FROM pg_class WHERE relname='my_table';

It might pay to have a quick glance at the documentation here [1].
It's important to know that relpages is *not* kept up-to-date every
time the relation size increases. It's probably most commonly going to
be updated by auto-analyze after the table has grown or changed enough
for an auto-analyze to trigger.

The actual answer to the question depends on what Otar wants to
include when counting the number of blocks. pg_table_size() will count
the TOAST table too. If that's what's required then Otar's original
query looks fine. If not, the table in [2] is likely going to yield
the answer. pg_relation_size() might be what's required.

David

[1] https://www.postgresql.org/docs/current/catalog-pg-class.html
[2] https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-DBSIZE

In response to

  • Re: at 2021-08-15 10:14:55 from Michael Goldberg

Browse pgsql-general by date

  From Date Subject
Next Message Michael Harris 2021-08-15 22:41:41 RE: ERROR: invalid memory alloc request size when committing transaction
Previous Message Digimer 2021-08-15 19:16:50 Single mater replica setup for an existing DB