1

After executing the query provided here, I got below result

Select  pg_relation_size(20473, 'main'),pg_relation_size(20473,'fsm'),
pg_relation_size(20473,'vm'),pg_relation_size(20473,'init'),pg_table_size(20473)
from pg_statio_user_tables

enter image description here.

Why am I not getting

pg_relation_size(20473,'main') + pg_relation_size(20473,'fsm') + pg_relation_size(20473,'vm') + pg_relation_size(20473,'init') = pg_table_size(20473)?
Community
  • 1
  • 1
YogeshR
  • 1,606
  • 2
  • 22
  • 43

2 Answers2

2

pg_relation_size calls calclulate_relation_size.

pg_table_size calls calculate_table_size.

calculate_table_size calls calclulate_relation_size and calculate_toast_table_size.

So when calling pg_table_size the TOAST-Data is added.

Link to Source Code

Ben H
  • 435
  • 5
  • 15
2

From the documentation:

pg_relation_size(relation regclass, fork text)
Disk space used by the specified fork ('main', 'fsm', 'vm', or 'init') of the specified table or index

pg_table_size(regclass)
Disk space used by the specified table, excluding indexes (but including TOAST, free space map, and visibility map)

So it must be the TOAST table.

Community
  • 1
  • 1
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263