Check the size of table in PostgreSQL

Check the size of table in PostgreSQL

pg_relation_size() function to get the table size. pg_size_pretty is used for human readable form.

SELECT pg_size_pretty(pg_relation_size('test'));

testdb=# SELECT pg_size_pretty(pg_relation_size('test'));
 pg_size_pretty
----------------
 8192 bytes


testdb=# SELECT pg_relation_size('test');
 pg_relation_size
------------------
             8192

Get the size of table and indexes for the table in PostgreSQL database:

pg_total_relation_size() function is used for get the table data size plus index size.

SELECT pg_size_pretty (pg_total_relation_size ('test'));

testdb=# SELECT pg_size_pretty (pg_total_relation_size ('test'));
 pg_size_pretty
----------------
 8192 bytes
(1 row)

Check the size of table with \d command:

testdb=# \d+
                                     List of relations
 Schema | Name | Type  |  Owner   | Persistence | Access method |    Size    | Description
--------+------+-------+----------+-------------+---------------+------------+-------------
 public | test | table | postgres | permanent   | heap          | 8192 bytes |
This entry was posted in PostgreSQL on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply