In this article, we will see how to find the table size in PostgreSQL. We can find the table size by using pg_relation_size. pg_relation_size returns the size of a table in bytes. If we want more readable format, use pg_size_pretty() function.
We can also find the size of PostgreSQL table, using meta command \dt+ table_name.
Find the table size in PostgreSQL examples:
1. Find the PostgreSQL table size using pg_relation_size.
select pg_size_pretty(pg_relation_size('customer'));
2. Find the table size with readable format like KB, MB or GB..
select pg_size_pretty(pg_relation_size('customer'));
3. Find the table size using meta-command in PostgreSQL Server.
\dt+ customer
4. Find the total size of the table including indexes and other spaces in PostgreSQL server.
select pg_total_relation_size('customer');