DEV Community

Frits Hoogland for YugabyteDB

Posted on • Updated on

YugabyteDB in-database visible object sizes

The PostgreSQL database has a number of very useful functions to calculate the size of the objects on disk. Examples of such functions are pg_table_size(), pg_indexes_size(), pg_tablespace_size(), etc, but also the ysqlsh/psql utility \d[tibm]+ commands to show the sizes of objects.

In YugabyteDB starting from version 2.15.3.0, YugabyteDB YSQL added the functionality to show the object sizes too.

If you wonder why this wasn't done before, it should be noted that because the storage of YugabyteDB via DocDB is so fundamentally different, it's impossible to just implement the PostgreSQL code. In fact, the code in PostgreSQL goes to the files for the given object, and measures the file sizes.

In YugabyteDB, such a request must be requested via an RPC message to DocDB, and the DocDB cluster must perform the size calculation.

The current implementation calculates the WAL file size plus the (compressed) SST file size for the leader tablets of an object.

This means the size calculation gives a close approximation of an object in an replication factor 1 cluster or in a table space with replication factor set to 1. If the replication factor is set to 3, then essentially the size must be multiplied by the replication factor to get an approximation of the object size/storage footprint.

There are some other caveats that must be taken into account:

  • For objects that are colocated, the size will be zero, because the WAL and SST files are shared with other objects.
  • For partitioned objects, the size of the parent does not include the size of the children.
  • YSQL will show the table and a primary key (_pkey) for a table with primary key, in reality there is no separate primary key index because the table rows are stored to be easy to be fetched via the primary key. Therefore the size of the primary key index will show 0.

ps. The functionality is available in YugabyteDB version 2.15.3.0, but is fully working with the latest preview release 2.15.3.2.

Top comments (0)