pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
explaining the pg_total_relation_size/pg_relation_size results
3+ messages / 3 participants
[nested] [flat]

* explaining the pg_total_relation_size/pg_relation_size results
@ 2018-06-20 22:26  Wells Oliver <wells.oliver@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Wells Oliver @ 2018-06-20 22:26 UTC (permalink / raw)
  To: pgsql-admin

I have the follwing in a view to glance at the size of my relations:

pg_size_pretty(pg_relation_size(c.oid::regclass)) AS size,
pg_total_relation_size(c.oid::regclass) AS bytes

This view sorts by pg_relation_size(c.oid::regclass) descending.

The question is: the byte values are often higher for relations with a
lower size indicated by size. As I sit here, I see an 11GB table
of 23821893632 bytes and a 12GB table of 14545387520 bytes, and
lastly/weirdly, a 3194MB table of 19924844544 bytes.

Can someone give me the quck explainer here of what I am looking at? I tend
to trust the size more than the bytes but I want to understand both better.

Thanks.

-- 
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: explaining the pg_total_relation_size/pg_relation_size results
@ 2018-06-20 22:42  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Wells Oliver <wells.oliver@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Alvaro Herrera @ 2018-06-20 22:42 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin

On 2018-Jun-20, Wells Oliver wrote:

> I have the follwing in a view to glance at the size of my relations:
> 
> pg_size_pretty(pg_relation_size(c.oid::regclass)) AS size,
> pg_total_relation_size(c.oid::regclass) AS bytes
> 
> This view sorts by pg_relation_size(c.oid::regclass) descending.
> 
> The question is: the byte values are often higher for relations with a
> lower size indicated by size. As I sit here, I see an 11GB table
> of 23821893632 bytes and a 12GB table of 14545387520 bytes, and
> lastly/weirdly, a 3194MB table of 19924844544 bytes.

This is a strange question.  pg_total_relation_size includes the size of
indexes and toast table and index, which pg_relation_size does not, so
it seems natural that they give wildly different results for differently
shaped tables.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: explaining the pg_total_relation_size/pg_relation_size results
@ 2018-06-20 22:44  David G. Johnston <david.g.johnston@gmail.com>
  parent: Wells Oliver <wells.oliver@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: David G. Johnston @ 2018-06-20 22:44 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin

On Wed, Jun 20, 2018 at 3:26 PM, Wells Oliver <wells.oliver@gmail.com>
wrote:

> I have the follwing in a view to glance at the size of my relations:
>
> pg_size_pretty(pg_relation_size(c.oid::regclass)) AS size,
> pg_total_relation_size(c.oid::regclass) AS bytes
>
> This view sorts by pg_relation_size(c.oid::regclass) descending.
>
> The question is: the byte values are often higher for relations with a
> lower size indicated by size. As I sit here, I see an 11GB table
> of 23821893632 bytes and a 12GB table of 14545387520 bytes, and
> lastly/weirdly, a 3194MB table of 19924844544 bytes.
>
> Can someone give me the quck explainer here of what I am looking at? I
> tend to trust the size more than the bytes but I want to understand both
> better.
>
> ​
https://www.postgresql.org/docs/10/static/functions-admin.html#FUNCTIONS-ADMIN-DBOBJECT

​The documented difference between the two size functions are "indexes" and
"toast" (and the non-main forks which are a small fraction of the
difference).  Any observation of an inverse relationship between the two
doesn't seem actionable...

Toast is basically "automatic large object storage"; I leave the docs to
cover indexes.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-06-20 22:44 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-20 22:26 explaining the pg_total_relation_size/pg_relation_size results Wells Oliver <wells.oliver@gmail.com>
2018-06-20 22:42 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2018-06-20 22:44 ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox