Display Table Size in YSQL

You can display the size of a YSQL table via the pg_table_size function.

Example:

				
					yugabyte=# CREATE TABLE test (c1 INT);
CREATE TABLE

yugabyte=# INSERT INTO test SELECT g FROm generate_series(1, 100000) g;
INSERT 0 100000

yugabyte=# SELECT pg_table_size('public.test') AS "Size in Bytes";
 Size in Bytes
---------------
       7520119
(1 row)
				
			

The pg_size_pretty function can be used to display the table size in a more user friendly and understandable measure, using kB, MB, GB or TB as appropriate.

				
					yugabyte=# SELECT pg_size_pretty( pg_table_size('public.test')) AS "Size in KiloBytes";
 Size in KiloBytes
-------------------
 7344 kB
(1 row)

yugabyte=# CREATE TABLE my_test2 (x BIGINT, y BIGINT, z BIGINT, PRIMARY KEY(x, y));
CREATE TABLE

yugabyte=# INSERT INTO my_test SELECT g, g, g FROM generate_series(1, 1000000) g;
INSERT 0 1000000

yugabyte=# SELECT pg_size_pretty( pg_table_size('public.my_test')) AS "Size in MegaBytes";
 Size in MegaBytes
-------------------
 63 MB
(1 row)
				
			

Have Fun!

Happy Tails Dog Park - Bradenton, FL